I currently have a script that is called to move an object back towards it original location and also restore the objects original rotation. The following two lines are called to do so:
Instead of rotating the object to its original rotation while moving the object towards its original location at the same time, the object first moves to its original position and then begins rotating. If issue 2 can be solved though this should not be an issue it is just strange that it is working that way
Instead of rotating the object around its center, rotate towards takes the object on a large circular path while returning it to its original rotation. For instance I have had cases where the object, in the process of rotating, rotates completely under the “floor” of the scene. Is there a way to avoid this unnecessary circular path?
This sounds like your object is not centered properly. i.e. its geometry, or pivot is not at 0,0,0
You can solve this by adding another parent object above it. Move that to 0,0,0 position in the world.
Then add your object as a child object, and move it so its also at 0,0,0 in the world.
Save your prefab.
Now when you do rotateTowards… it should rotate around the center properly.
Second issue… rotate towards… doesn’t move how you want it to…
Try using vectors directly instead… they are much more flexible…
for example… get a vector from target to your current object… Vector3 lookAt = target.pos - my.pos;
Then get a difference vector between your current object’s look and that lookAt vector…
Vector3 delta = lookAt - myObj.transform.forward;
now you have power to move your object towards the target look however much you like…
myObj.transform.forward = lookAt; //instantly look at target
myObj.transform.forward += delta *.1 * Time.deltaTime; // slowly look towards target… smoothed
or store starting forward vector… then do a linear or circular lerp (curve)
myObj.transform.forward = Vector3.Lerp( startVec, targVec, lerp01); //where you move the lerp param from 0-1 over time.