News Forums RAIN General Discussion and Troubleshooting How to get the 'desired velocity' or desired facing direction of the navigator

This topic contains 3 replies, has 2 voices, and was last updated by  AdamR 1 year, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38213

    AdamR
    Participant

    With the Unity navmeshagent, I can get the desired velocity (intended direction of the nav mesh agent) and force the agent to move at an actual velocity (speed and direction) of my choosing.

    Is there an equivalent way to get this information from the RAIN AI rig’s Navigator?

    I’ve found this post to be somewhat helpful, but I don’t see where the the navigator’s desired move direction is accessed.
    http://rivaltheory.com/forums/topic/setting-up-custom-motion/

    #38223

    AdamR
    Participant

    To be more specific, I’d like to replicate my current functionality which uses Unity’s navMeshAgent.

    The navMeshAgent provides a desired velocity, which is used by the animator to get the correct walk cycle (via magnitude) and desired direction (which does not affect the animator).

    I set the actual navMeshAgent’s velocity to the animator.deltaPosition / deltaTime.

    I allow the navMeshAgent to directly update the position (but not rotation) of my game object, this way my object *never* leaves the navmesh and it is moving at the animation’s root motion speed. On a side note, I’ve noticed that the RAIN navigation appears to rely on the physics colliders to traverse in the Y axis? Is there any way to have objects move up an inclined path with a kinematic collider and not adding additional raycasts? This is a nice feature the Unity has where the game object will not leave the mesh in any direction.

    I update the rotation of the the game object on my own, as I said above. I do not use dedicated turn animations.

    Reading the RAIN API, I think the AI.Kinematic is roughly analogous to the Unity navMeshAgent in regards to getting the current position that will be evaluated by the navigation algorithms and the intended direction?

    #38237

    prime
    Keymaster

    After a call is made to Move in the RAIN Motor, the AI Kinematic structure (as you mentioned) is updated with a desired Velocity and Rotation. You are free to set/override those yourself.

    The results of the desired Velocity/Rotation are computed in the Motor’s ApplyMotionTransforms() method, which you can override if you need to by creating a custom motor that inherits from whichever motor you are using. ApplyMotionTransforms is called by the AI Act() method.

    So, the easiest way to insert something into the motion pipeline is to create a custom motor from one of the built-ins. Then override ApplyMotionTransforms and update the Kinematic before calling base.ApplyMotionTransforms().

    You might also note that the Mecanim Motor has an option to Override Root Motion Rotation if you want the motor to separately manage rotation from forward locomotion (i.e., not rely on rotations built into your animation). If you check that box, then you can let the motor deal with rotation itself (which is probably the result you are looking for) or you can set a Face target on your own.

    #38287

    AdamR
    Participant

    This is the solution I came up with, appears to work as desired. This only solves the issue of removing translation/rotation control from the RAIN motor. Another script will handle keeping the object restricted to the mesh.

    using System.Collections;
    using RAIN.Core;
    using RAIN.Motion;
    [RAIN.Serialization.RAINSerializableClass]
    public class My_RAINMotor : BasicMotor {
    	/// UpdateMotionTransforms updates the AI Kinematic structure with the current
    	/// values associated with the AI Body.
    	/// </summary>
    	public override void UpdateMotionTransforms()
    	{
    		this.AI.Kinematic.Position = AI.Body.transform.position;
    		AI.Kinematic.Orientation = AI.Body.transform.rotation.eulerAngles;
    		AI.Kinematic.ResetVelocities();
    	}
    	/// <summary>
    	/// ApplyMotionTransforms applies physical forces back to the AI Body
    	/// </summary>
    	public override void ApplyMotionTransforms()
    	{
    		AI.Kinematic.UpdateTransformData(AI.DeltaTime);
    		//We handle the actual translations and rotation of the character in another script
    	}
    }
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.