0 Favourites

# AI sprite change anim based on trajectory

• 3 posts
• I know how to change the player sprite/animation based on whether they are moving up, down, or left and right to imply movement. What I can't figure out is how to make an entity not controlled by the player do the same. The enemy doesn't have a "patrol" per se. He kind of wanders in a random fashion bouncing off solids. But every few seconds I have it reset it's angle to face the player, giving a vaguely "zombie like AI pathfinding" (also repositions angle based on "loud" elements caused by the player...etc. Anyways, I can think out the math but can't figure out how to make construct agree with me :)

If your x speed (absolute) is greater than your y speed (absolute) then you are moving predominantly on the x axis or left/right.

If your x speed is negative you are heading left = play "walk_left" anim

or

If your y speed (absolute) is greater than your x speed (absolute) then you are moving predominantly on the y axis.

If your Y speed is positive you are heading up = play "walk_up" anim

and so forth. But I can't find the ability to compare x and y speeds so I can start making this determination. Am I over or underthinking this?

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Hey Tporter,

Have you looked at using the "Is between angle" to play the right animation instead? That should cut a lot of the math work anyway :)

• yeah, Is between angle works pretty well for switching now. I'm basically trying to get the AI and animation behavior of say the guards in Zelda: LTTP. They kinda do their own thing and upon drawing aggro start approaching the player, of course I don't need my guys to move diagonally. Thanks for the idea. I knew there was a quality shortcut.

• 3 posts