AI vaulting over object. How would YOU do it?

Hey,

I’m working on a zombie FPS and there are going to be dynamic objects the player can move around. Since they are dynamic they will not be baked into the NavMesh. So the zombies could try and walk straight through them.

However, there are certain types of zombies that when approaching these dynamic objects they will jump over the top of them.

How will you guys do this? How will you check to make sure nothing is on top of that object? How would you check how high they need to climb? How would you check how far they need to walk before they can jump off of the other side?

Theories? pseudo-code? examples?

Thanks,
why789

Raycast in front of them at the height of their face to determine if something is short enough for them to climb onto. (Assuming they can’t climb something taller than them.) Once on top of the object you can either just let them fall off the other side or if you want to do something event driven raycast downward at a point slightly in front of them to determine when they reach the edge of the object.

Most games I haev worked on in the past use specific materials on surfaces that any player interacts with differently.

You should kow that what you are doing is not going to be easy and for very little benefit, especially with the part abou these objects being completely dynamic and I’m guessing not hte same size.

Were I to do it…I would use offset vectors from the character root to do raycasts to the collision hull in fron tof the charater. But it’s going to get messy and look off. Why? because you cant just play an animation of a character clawling over any surface at any angle, that doesnt work. You could do the jump that isnt hard. But if you want the zombie to natuarally spiderman over a jumbo jet it’s going to be an enourmous amount of work on your part, raycasting for each hand and foot, playing an animation for each limb then at the same time controlling the tilt of the body. You are really opening a can of worms for yourself.

at jump height level, raycast forward
did it hit ( if so we climb)
( if not jump over )
did we jump far enough over? ( if so we land bcak on ground )
( if not we land on object )
get normal of surface straight down below us
blend appropriate animations to achieve that angle of stance
jump again?

if climb over…get normal of surface that is forward of hand grab height, forward of each foot
play appropriate animation on each to make contact
for each frame, calculate vector from each hand/foot current position to it’s next raycasting for each
blend the appropriate amount of animation for each
if limbs stretch to far adjust body position and angle

the flow would go something like that but much more detailed as you would be blending each limb with three animation states ( not fun )

I’m writing a similar game myself, what I did was to create a script for each interaction type. Then when your AI hits a point (like a wall) you raycast (or sphere collision, or pull from pathing api, etc… ) to get the GO in question. Then do a check via GetComponent<> to see if there is a usable interaction attached. So for instance, you could create a IsClimbable script, attach it, then maybe have some parms to tweak how tall the monster must be, time to climb modifiers, maybe events that trigger on climbing, etc… all in your IsClimbable. Inside the AI controller, you’d have something like:

public void OnObstacle( GameObject obstacle )
{
IsClimbable climbable = obstacle.GetComponent( );
if( climbable != null ) {

}
}

The nice thing about this approach is in the editor, you just drop the appropriate interaction type(s) on a given object and away you go, plus you can customize particlar interactions, etc…

You could use layers, tags, etc… too, whatever floats your boat - in the end it depends on what works best for you.

I was thinking that this would be as hard as rungy suggested it :smile:
I think however that instead of vaulting over something I will do a basic leap :slight_smile: that will still look completely natural and it will make my job a lot easier,

Thanks for the help guys!

why789