Great solution. Just keep in mind that this will rotate the local X axis of the Entity towards the target so make sure to set up your objects to take this into account. Or you can add a Deg offset on the last line. For example, a offset of -90f will rotate the Y axis to the mouse position. this.transform.rotation = Quaternion.Euler(0, 0, AngleDeg + DegOffset);
public GameObject fish;
void Update () {
//keep the z position of the gameobject, LookAt the x and y position
Vector3 LookPos = new Vector3(fish.transform.position.x,fish.transform.position.y,transform.position.z);
gameObject.transform.LookAt (LookPos);
}
Make sure the the local blue axis of the shark points forward.
Thanks it works!!!
– The97Pasquale2Thank you so much!!!
– Totoajaxthanks this helped me a ton in 2017!
– vittu1994Really good solution!
– dyhmichailGreat solution. Just keep in mind that this will rotate the local X axis of the Entity towards the target so make sure to set up your objects to take this into account. Or you can add a Deg offset on the last line. For example, a offset of -90f will rotate the Y axis to the mouse position. this.transform.rotation = Quaternion.Euler(0, 0, AngleDeg + DegOffset);
– BeardTrigger