BD - Lock Rotation

dumbgamedev

New member
I am trying to lock the navmesh agent (UCC) during movement. However, it always rotates to its movement direction.

Here is the code of the task. Basically I am using it to move my character right, left, forward or back of his current position by offset. Ideally the rotation should lock, or the UCC character continues to look at the target (ideal).

This does set without any errors, but the rotations still continue.

Code:
            // Get ref to navmesh agent and lock rotation
            _agent = this.gameObject.GetComponent<NavMeshAgent>();
            if (_agent == null) Debug.LogError("No navmesh agent found for movement offset BD action");
          
            if (_agent != null)
            {
                _agent.updateRotation = false;
                Debug.Log("This agent has rotation set to " + _agent.updateRotation);
            }

Here is the full BD task.


Code:
using UnityEngine;
using UnityEngine.AI;

namespace BehaviorDesigner.Runtime.Tasks.Movement
{
    [TaskDescription("Move to an offset position")]
    [TaskCategory("Movement")]
    [TaskIcon("Assets/Behavior Designer Movement/Editor/Icons/{SkinColor}MoveTowardsIcon.png")]
    public class MoveOffset : NavMeshMovement
    {
        public SharedVector3 offsetPosition;
        public SharedBool enableDebug;

        private Vector3 _myNewPos;

        // Component references
        private NavMeshAgent _agent;

        public override void OnStart()
        {
            
            // Get ref to navmesh agent and lock rotation
            _agent = this.gameObject.GetComponent<NavMeshAgent>();
            if (_agent == null) Debug.LogError("No navmesh agent found for movement offset BD action");
          
            if (_agent != null)
            {
                _agent.updateRotation = false;
                Debug.Log("This agent has rotation set to " + _agent.updateRotation);
            }


            CalculateTargetPosition();
            base.OnStart();
            SetDestination(_myNewPos);
        }

        // Seek the destination. Return success once the agent has reached the destination.
        // Return running if the agent hasn't reached the destination yet
        public override TaskStatus OnUpdate()
        {
            if (HasArrived())
            {
                _agent.updateRotation = true;
                return TaskStatus.Success;
            }

            SetDestination(_myNewPos);

            return TaskStatus.Running;
        }

        // calculate target position
        private void CalculateTargetPosition()
        {
            _myNewPos = transform.TransformPoint(offsetPosition.Value);
            if (enableDebug.Value) DebugExtension.DebugWireSphere(_myNewPos, Color.red, 0.5f, 2f, true);
        }

        public override void OnReset()
        {
            base.OnReset();
            offsetPosition = Vector3.zero;
        }
    }
}
 
The character rotation is controlled by UCC so you'll need to create an ability which sets this rotation. You can then use BD to start/stop that task.
 
The character rotation is controlled by UCC so you'll need to create an ability which sets this rotation. You can then use BD to start/stop that task.

Are there any abilities right now that set/control rotation that I can look at the see how it is being done?
 
You can take a look at the Use and Aim abilities which update the rotation.
 
Top