Hip Rotation Node

Ramarolo

Member
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?
 
Last edited:
Please use [ code ] tags so it's easier to read.

With that said, in your task you are returning success/failure on the first tick. This will only update the rotation once and you likely need to keep updating it in order to fully rotate.
 
You´re right, before asking I tested it in a Parallel node, so it is calling it in every branch tick, but yes it is debugging one per shot with this structure
1701426231928.png
But the point is that the call has to be constant in this branche, I tried also with a repeater to try Update the RotateObject node in each frame
1701426401398.png
And other kind of approaches, but I do not want to full the topic of phtos.

How can I call this node in every frame in this branche? Any another approach or node structure?

Thanks for replying
 
The easiest solution without restructuring your tree would be to have Rotate Object return success as soon as it has been rotated to the target position, rather than have it return success immediately. This is what the Rotate Towards task does.
 
Top