RichAI - Overriding RotateTowards() Makes Agents Move Slower

Hi,

Is it possible to manually control the direction a gameObject is facing (transform.forward) while it moves along its path?

I have read in these forums that writing an override for RotateTowards will allow control over this:

I have experimented with changing the RotateTowards defined in RichAI, but whenever the gameObject is not facing in the direction of travel the velocity is slow.

If you comment out the contents of the RotateTowards() method (except for return false), the gameObject still moves on its path but stays facing the same direction (i.e. does not rotate). However, it is much slower when not moving along the gameObject’s +x-axis (transform.forward).

I want to define the gameObject’s transform.forward while it is moving on its path, and always have it move at the same speed regardless of the direction of transform.forward.

Hello again,

I think I may not have been clear about what I’m asking. Ok i’m a rambler.

  1. When I override “RotateTowards” contained in RichAI.cs I can easily control the direction of transform.forward during travel.

  2. When the transform.forward is not the same as the direction of travel (path direction), the speed of the agent is decreased. This speed decrease is proportinate to the transform.forward’s angle away from the direction of travel. When transform.forward is facing 180-degrees away from direction of travel, the agent is slowest.

  3. So… what is causing the transform to travel slowly when the agent’s transform.forward is not the direction of travel?

Hi

There is a field on the RichAI named “slowWhenNotFacingTarget” if you uncheck that it will not move slower when it is not facing the target.

The actual code that makes it move slower is the Vector3.Dot call around line 426

if (slowWhenNotFacingTarget) {
    float dot = (Vector3.Dot (normdir, tr.forward)+0.5f)*(1.0f/1.5f);

The Vector3.Dot function returns 1 when the vectors point in the same direction, 0 when they are perpendicular and -1 if they point in exactly opposite directions.

Thanks for the reply!

I see it now. Can’t believe I overlooked that!

Thanks again!

1 Like