Hi,
I want to know what system you use to rotate an object, I do not mean the RotateTowards node that rotates the object having the BT, I mean a node to rotate a specific object, like in my case, the hip of an agent, to look the player. The agent himself already rotates to the player with rotateTowards node, but it needs the hip rotation when the player is in a different terrain elevation.
I guess I tried all nodes named "Rotate..." in the asset, but are not for a specific object, only for the full agent. So, I created one customized unsuccessfully (of course I filled the Shared slots and assigned values to public varialbes):
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using UnityEngine;
public class RotateObject : Action
{
[SharedRequired]
public SharedTransform target;
[SharedRequired]
public SharedTransform rotateMe;
public float rotationSpeed;
public Vector3 rotationOffset;
public override TaskStatus OnUpdate()
{
if (target.Value != null && rotateMe.Value != null)
{
Vector3 directionToTarget = (target.Value.position - rotateMe.Value.position) + rotationOffset;
Quaternion lookRotation = Quaternion.LookRotation(directionToTarget, Vector3.up);
rotateMe.Value.rotation = Quaternion.Slerp(rotateMe.Value.rotation, lookRotation, Time.deltaTime * rotationSpeed);
Debug.Log("rotating object: " + rotateMe.Value.name + " rotating to " + target.Value.name);
return TaskStatus.Success;
}
return TaskStatus.Failure;
}
}
Please, help me, how would you solve this situation?
I want to know what system you use to rotate an object, I do not mean the RotateTowards node that rotates the object having the BT, I mean a node to rotate a specific object, like in my case, the hip of an agent, to look the player. The agent himself already rotates to the player with rotateTowards node, but it needs the hip rotation when the player is in a different terrain elevation.
I guess I tried all nodes named "Rotate..." in the asset, but are not for a specific object, only for the full agent. So, I created one customized unsuccessfully (of course I filled the Shared slots and assigned values to public varialbes):
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using UnityEngine;
public class RotateObject : Action
{
[SharedRequired]
public SharedTransform target;
[SharedRequired]
public SharedTransform rotateMe;
public float rotationSpeed;
public Vector3 rotationOffset;
public override TaskStatus OnUpdate()
{
if (target.Value != null && rotateMe.Value != null)
{
Vector3 directionToTarget = (target.Value.position - rotateMe.Value.position) + rotationOffset;
Quaternion lookRotation = Quaternion.LookRotation(directionToTarget, Vector3.up);
rotateMe.Value.rotation = Quaternion.Slerp(rotateMe.Value.rotation, lookRotation, Time.deltaTime * rotationSpeed);
Debug.Log("rotating object: " + rotateMe.Value.name + " rotating to " + target.Value.name);
return TaskStatus.Success;
}
return TaskStatus.Failure;
}
}
Please, help me, how would you solve this situation?
Last edited: