Hi there, I'm new to scripting and trying to adapt some scripts I purchased on the asset store for AI agents to have animations. My question is whether there is a way to adapt this line of code so that it performs the rotation smoothly over a 1 second, currently it just snaps them into the rotation: Code (CSharp): //Rotate agent towards LookAt gameObject.transform.LookAt(needsimNode.Blackboard.activeSlot.LookAt); Thank you for any help.
https://docs.unity3d.com/ScriptReference/Quaternion.RotateTowards.html If you want it to be exactly 1 second regardless of distance, you can use slerp instead but that's more complicated.
Hi, Thanks for your response. It doesn't need to be exactly 1 second, just blend instead of snapping before entering the next state. Could you possibly show me what the line of code would be?
When you're new to coding, everything can seem tough. The RotateTowards takes parameters: current rotation, target rotation, and max degrees delta. Code (csharp): Vector3 direction = other.transform.position - transform.position; Quaternion rot = Quaternion.LookRotation(direction); transform.rotation = Quaternion.RotateTowards(transform.rotation, rot, 10 * Time.deltaTime); // 10 could be a variable for rotation speed. Something like that. I would suggest that you follow some tutorials to help get started: https://unity3d.com/learn/beginner-tutorials https://unity3d.com/learn/tutorials/lets-try https://unity3d.com/learn/tutorials/s/scripting