Rotate Towards in Behavior Tree

KO_Games

Member
Hi Justin,

I'm trying to get the rotate towards task working with behavior tree. I'm using the opsive third person controller, behavior tree, and a* pathfinding project. I want my ai to rotate very quickly towards the target gameobject. The issue that I'm running into is it seems that rotate towards seems to get stuck in the running status, so my behavior tree won't progress to the next task. My character rotates just fine and faces the target, but then the status keeps running. I tried adjusting the rotation epsilon angle to a higher amount, but it didn't seem to help unless it got very high. Here are my settings. Is this because I'm using A* pathfinding instead of the unity navmesh?

behavior screen shot.png
 
Rotate Towards modifies the transform directly which won't work with the controller because the controller has control over the transform. You'll need to create a new ability that instead rotates the character.
 
I tried to do a rotate towards ability following this thread from the forum as a guide, but I'm getting stuck. I don't see the deltayaw option anymore. I also tried following the aim ability, but I couldn't get my ai character using behaviour tree to rotate and face the gameobject I wanted them to face. I'm not sure what I'm missing. Here is my code:

C#:
public class RotateTowardsNew : Ability
{
    private float _maxRotationAngle = 10000; // turnSpeed
    public GameObject _targetGO;

    public override void ApplyRotation()
    {
        var angle = Quaternion.Angle(Quaternion.identity, m_CharacterLocomotion.Torque);
        if (angle > _maxRotationAngle)
        {
            m_CharacterLocomotion.Torque = Quaternion.Slerp(Quaternion.identity, m_CharacterLocomotion.Torque, _maxRotationAngle / angle);
        }
    }

    public override void UpdateRotation()
    {
        var agentPos = m_CharacterLocomotion.transform.position;
        var lookDirection = _targetGO.transform.position - agentPos;
        var rotation = m_Transform.rotation * Quaternion.Euler(m_CharacterLocomotion.DeltaRotation);
        var localLookDirection = m_Transform.InverseTransformDirection(lookDirection).normalized;
        localLookDirection.y = 0;

        lookDirection = MathUtility.TransformDirection(localLookDirection, rotation);
        var targetRotation = Quaternion.LookRotation(lookDirection, rotation * Vector3.up);
        m_CharacterLocomotion.DeltaRotation = (Quaternion.Inverse(m_Transform.rotation) * targetRotation).eulerAngles;

        base.UpdateRotation();
    }
}
 
DeltaYaw is no longer in the current version. Taking a look at the Aim ability is a good example. You can debug this by multiplying the DeltaRotation by the current rotation to see if it's pointing in the direction that you'd expect. In a future release I can add a rotate towards ability.
 
Hi Justin. I'm not sure what you meant by debugging this by multiplying the DeltaRotation by the current rotation to debug. Can you give me an example?
 
The rotation that the character will rotate to is:

Code:
transform.rotation * Quaternion.Euler(deltaRotation)
 
Top