Support Forum

Directly setting rotation of RichAI?

Is there a fool-proof way of setting a RichAI’s rotation manually? I know that I can set enableRotation to false and then just change the transform.rotation. I do it like that to let my character look into a specific direction while it doesn’t walk a path.

But when I then set RichAI’s enableRotation to true again (to let it follow the path correctly), the character seems to try first to snap back to the old rotation from before I did enableRotation = false. It should accept the new transform.rotation from the start, but I can’t set RichAI.rotation because it doesn’t have a setter.

Instead of changing enableRotation and setting the transform.rotation directly I now change canMove and call MovementUpdate() and then change the rotation via FinalizeMovement. I guess that’s the more correct way to do this?

Jup, any custom rotations etc must be done before FinalizeMovement

Hi

Good point, I have now added a setter for the rotation property as well (it will be included in the next beta).
However, note that this will just set transform.rotation directly (unless updateRotation is set to false, but I don’t think that’s the case for you).

1 Like

Hey guys I just found myself in the same position. What’s the status at this moment? (I am using the beta branch). I am making a facing wall check when I stop moving, so I can turn back and look to other places, but when I set the rotation after the AI arrives (I do it on the pathCallback when it returns reachedDestination as true), it does it for a frame and then it goes back to the rotation before that one. What should be the correct way of setting some rotation manually (at least until I get moving again)? I tried the FinalizeMovement but does the same for me.

Thanks!

From what I can find on the forum there is no real answer to this question, seeing as I want to do the same thing my self. You can set the rotation but it will always rotate back to the AI rotation afterwards. Is there no simple way to override the rotation of the ai isntead of just altering the transform?

I faced same issue,kinda bypass it with putting my logic in Late Update but when ai was transversing on NodeLink at the end point it again rotated back to wronng direction. I ended up fixing rotatioon in Update loop when he was transversing to fix it.

Hi

If you want different rotation logic I’d recommend setting ai.updateRotation = false. Then in your update function you can set the Transform’s rotation to whatever you want. You can read from the ai.rotation property to find out what the AI’s rotation would have been if it had been allowed to control its rotation.

Setting the transforms rotation is no problem really. The code I use to do that now is:

public void ForceRotation(Vector3 rotation)
    {
        agent.rotation = Quaternion.Euler(rotation);
        aiPath.enableRotation = false //Without this it simply rotates back to whatever direction it was facing
    }

I think the problem is that there is something I don’t understand about how this works. In my mind setting agent.rotation should set the agents rotation, but it seems to only set the transforms rotation. Meaning it will rotate back in whatever direction it was facing.

If you do as you suggest and set ai.updateRotation = false, or simply disable rotation. That works UNTIL you have to re-enable rotation again, then the actual ai rotation is still facing the last direction it was facing, even though the transform looks correct.

If im being unclear I can post some screenshots.

Hi

The agent always rotates towards the direction it is moving in. That’s the only rule it has.