Hi all,
I have a Trolley in my game which Rotates around the player (GIF Below for Example) I am trying to make it so the Trolley doesn’t ‘Skid’ sideways when the player moves the Camera.
GIF Example:

I attempted to use Animation Events to achieve this though it is a little slow and sometimes doesn’t work as shown below.
GIF Example:

I am wondering if there is a way that this can be done through C# to make it more fluent and making it so the Tolley’s force toward the rotating direction is increased as the rotation (difference) is greater, when the Camera Rotation slows the rotation force of the Trolley eases off, when there is little to no Camera Movement it should be returned to normal forward facing direction.
This is the code currently used to handle the Trolleys rotation (with the Update function):
camRotY = camRot.eulerAngles.y;
if (trollieRot.eulerAngles.y != camRotY)
{
float diff = 0;
Debug.Log("Camera Rot Y is: " + camRotY);
diff = Math.Abs(camRotY - lastYRot);
if (diff < 1)
{
anim.SetBool("left", false);
anim.SetBool("right", false);
anim.SetBool("idle", true);
}
else
{
if (lastYRot < camRotY)
{
anim.SetBool("left", false);
anim.SetBool("right", true);
anim.SetBool("idle", false);
}
else if (lastYRot > camRotY)
{
anim.SetBool("left", true);
anim.SetBool("right", false);
anim.SetBool("idle", false);
}
}
trollieRot.eulerAngles = new Vector3(
trollieRot.eulerAngles.x,
camRotY,
trollieRot.eulerAngles.z
);
lastYRot = camRotY;
}
For Example something like this but more dynamic that the rotation is basically directly affected by the current difference:
if(diff == 0.1){
//rotate a little bit
}
if(diff == 0.5){
//increase rotation angle
}
if(diff => 1){
//use max roational angle
}
