Hello, I want to use RotateTowards (or any other way to do this if you have a suggestion) to make my object (Obj1) face towards another that has been defined by an event (Obj2, marked as the goal when a separate collider connected to the same pivot hits it.)
When the player lets go of Obj1 I would like it to rotate towards facing Obj2, and then stop once facing it.
I’ve attempted to do angles and stuff but I just can’t get it to work properly.
public void SetLastNotch(GameObject notch)
{
lastNotch = notch;
}
public IEnumerator NotchSnap()
{
GameObject pivot = transform.parent.gameObject;
Vector3 dirFromAtoB = (lastNotch.transform.position - pivot.transform.position).normalized;
float dotProd = Vector3.Dot(dirFromAtoB, pivot.transform.up);
print(dotProd);
while (dotProd > 0.9)
{
print("rotate");
pivot.transform.rotation = Vector3.RotateTowards(pivot,dotProd);
yield return new WaitForSeconds(0.1f);
}
StopAllCoroutines();
}
This is my code so far. lastNotch is the object that was last touched by a separate hitbox.
TL;DR: Rotate “pivot” to look at lastNotch and then stop when it is aligned (within a certain tolerance i guess?)