News Forums RAIN Sample Projects, How To, and Code Motion Controller, Unity NavMesh and RAIN Example Motor

This topic contains 0 replies, has 1 voice, and was last updated by  blockcipher 3 weeks, 6 days ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #40400

    blockcipher
    Participant

    Here is a simple Motor I made to make RAIN work with Motion Controller (https://www.assetstore.unity3d.com/en/#!/content/15672) and the Unity NavMesh.

    1) Place a RAIN AI component on your character (Menu > RAIN > Create New > AI)
    2) a) Place a MotionController on your character (Menu > Component > ootii > Motion Controller)
    b) Make sure MC placed a NavMesh Input Source on your character. If it didn’t, add one.
    3) Place a NavMeshAgent on your character
    3) Setup the Motion Controller however you want it
    4) Change the Motor (under the RAIN AI Motion tab) to McRAINNavMeshMotor (code follows) (at the moment it doesn’t have any exposed properties that will show up in the inspector)

    Since the controller uses Root Motion to control speed, you can use a “Speed Multiplier” variable, set up in the Animator, to control the character speed. This is (I believe) a new feature and is present in Unity version (5.3.4p4)

    The position data is fed to the NavMeshAgent from RAIN through the MotionController.

    Have fun! If you have any problems you can ask here or send me an email at (anarchyrising420@gmail.com)

    using UnityEngine;
    using System.Collections;
    using com.ootii.Actors.AnimationControllers;
    using com.ootii.Input;
    using RAIN.Motion;
    using RAIN.Serialization;
    [RAINSerializableClass]
    public class McRAINNavMeshMotor : RAINMotor
    {
        private NavMeshInputSource _mcInputSource;
        public override void BodyInit()
        {
            base.BodyInit();
            _mcInputSource = AI.Body.GetComponent<NavMeshInputSource>();
            if (_mcInputSource == null)
                Debug.LogWarning("MC Input Source was not found!");
        }
        public override void UpdateMotionTransforms()
        {
        }
        public override void ApplyMotionTransforms()
        {
        }
        public override bool Move()
        {
            if (!MoveTarget.IsValid)
                return false;
            _mcInputSource.TargetPosition = MoveTarget.Position;
            return IsAt(_mcInputSource.TargetPosition);
        }
        public override bool Face()
        {
            return true;
        }
        public override void Stop()
        {
            _mcInputSource.ClearTarget();
        }
        public override bool IsAt(MoveLookTarget aTarget)
        {
            return IsAt(aTarget.Position);
        }
        public override bool IsAt(Vector3 aPosition)
        {
            Vector3 m_position = AI.Body.transform.position - aPosition;
            m_position.y = 0f;
            return m_position.magnitude <= _mcInputSource._StopDistance;
        }
        public override bool IsFacing(MoveLookTarget aTarget)
        {
            return true;
        }
        public override bool IsFacing(Vector3 aPosition)
        {
            return true;
        }
    }
    • This topic was modified 3 weeks, 6 days ago by  blockcipher.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.