News Forums RAIN General Discussion and Troubleshooting Keep enemy facing the player while strafing

This topic contains 1 reply, has 2 voices, and was last updated by  Sigil 1 month, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #39583



    I’m trying to implement a system where by, when an enemy is waiting to attack the player it will strafe in a random direction while waiting, just so I don’t have it standing like a statue in between attacks. At the moment I can make random locations on the mesh for it to move too, however it always faces the location as it moves rather than keeping fixed on the player which is what I want. When I try and use something like ai.Body.transform.LookAt(player), to try keep it focused on the player it ends up moving around the player in a circle and doesn’t actually go to the right locations set. Is there some way of separating say, the AI so it is attached to a game object and has the enemy as a child object so the two are free to rotate independently? Its something I tried out but as my animations use root motion the two objects seem to move at different speeds and it gets messed up. Any help would be appreciated.




    So it depends on what you need. Normally you can get away with setting your facing target different from your move target in the behavior tree. This will point the AI somewhere else and attempt to continue to move them to the original target.

    In order to handle this properly in your animations (root motion or not) you would need to forward the velocity variables (X and Z) from the Mecanim Motor to your state machine. We usually setup a 2 dimensional blend tree there using +/- Z for moving forward and backwards and +/- X for moving right and left.

    Does that make sense?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.