How to make a Spider in UE4 Part 1

Wall walking, ceiling walking, going around corners, etc.

This will blog my progress through doing this small project. It will primarily be done in C++ and I won’t go into details of making the model or animations, but I will show how I set those up once they have been imported into the Engine.

 

SimpleCast

 

For the spider to be able to walk up walls, transfer onto the ceiling, or even around corners on walls it needs to be able to detect when it can.

I choose to create Sockets on the skeleton and then get there location in C++ to perform traces.

SpiderSockets

 

In C++, get the location and then run traces from the Socket above, to the separate feelers in front, down and diagonal.

Note: I need to find a better syntax highlighter for WP, this is WP-Code-Highlight. Recommendations are welcome. The right arrows are inconsistent.

 

// Tick animations before physics.
if (CharacterOwner->GetMesh())
{
const FVector Start = CharacterOwner->GetMesh()->GetSocketLocation("DetectionSocket");

const FVector FLSocketLocation = CharacterOwner->GetMesh()->GetSocketLocation("FL");
const FVector RLSocketLocation = CharacterOwner->GetMesh()->GetSocketLocation("FR");

FHitResult HitDataFL(ForceInit);
FHitResult HitDataRL(ForceInit);

if (Trace(CharacterOwner, Start, FLSocketLocation, HitDataFL, ECollisionChannel::ECC_Pawn, false, true))
{
   //Print out the name of the traced actor
   if (HitDataFL.GetActor())
   {
            print(HitDataFL.GetActor()->GetName());
    }
}

if (Trace(CharacterOwner, Start, RLSocketLocation, HitDataRL, ECollisionChannel::ECC_Pawn, false, true))
{
   //Print out the name of the traced actor
   if (HitDataRL.GetActor())
   {
       print(HitDataRL.GetActor()->GetName());
   }
}

 

This will provide the actor under each hit. This method alone would require a naming scheme to be implemented in all the levels to actually use it, so it is just for debugging. We will test the angle on hits to determine whether it’s a transition and what type.

It can be seen in the below picture, how the right feeler detects a hit, and the left does not.

SpiderFeelers

 

In the next picture, if you look at the printed comments you can see that the floor and wall are detected separately.

SpiderWallFloorDetection

Share Button

Comments

How to make a Spider in UE4 Part 1 — 1 Comment

  1. To Mike Purvis

    Hi, I’m Junyep in Korean student who is studying unreal first time.

    First, thanks to post your work. It’s really impressive.

    So I want to apply this tutorial to the player of the game. but this tutorial is for a.i character.

    I’m wondering if this tutorial can apply it to a character and if not, I would like to ask you for advice.

    Thank you for reading my question and have a nice day

    Yours faithfully,
    Junyep Oh

Leave a Reply

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