How to make a Spider in UE4 Part 2

SpiderHitNormal

 

Picking up from Part 1 where we left the Spider able to detect what surface is in front and under itself.

The next step is to get the surface angle of the detected object. The main reason is we want this Spider to be able to navigate any landscape and level geometry made in the Editor, and not just geometry that has been marked up with special tags for querying.

The FHitResult contains the ImpactNormal. This is the Normal of the surface, regardless of the angle the trace intersected at.

I added another trace directly down so that a comparison could be done. The above screenshot shows the results of the traces. The Floor shows a Z value of 1, and the Wall shows a Y of -1.

The walls will have a non zero value in X or Y, and the floor and presumably ceiling will have a non zero value in Z. Testing just against if an X or Y would equal a -1 or 1 would mean the spider would only think it could go up perfectly orthogonal walls. But, just testing if Not Zero found hits everywhere.

if (HitNormal.Y <= -0.02 || HitNormal.Y >= 0.02 || HitNormal.X <= -0.02 || HitNormal.X >= 0.02)

I picked up some “principals” of good practice that I try to adhere to when programming. One of them is not to use “Magic Variables”. In the above test 0,02 is a magic variable. I’ll change it out for a named one; maybe, “WallTestThreshold”.

 

Now that the Spider can tell when it can transfer to a wall, the next step is to actually transfer it.

ICanWallWalk

 

Share Button

Comments

How to make a Spider in UE4 Part 2 — 2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *