How to rotate the object when you move to always look at the same point
I have a Paddle that rotates following the shape of the circle, the problem is that I need the concave part of the Paddle to face the center, that is, rotate its Y axis from 0 to 180 to look at the center.
the code to move following the circle
float timecounter = 0;
public Transform target;
public float speed = 3.0f;
public float width = 100.0f;
public float height = 100.0f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
// movimiento circular
timecounter += Time.deltaTime * speed;
float x = Mathf.Cos(timecounter) * width;
float y = 3;
float z = Mathf.Sin(timecounter) * height;
transform.position = new Vector3(x, y, z);
}
}
i try transform.LookAt and the Quaternion.LookRotation but i can't make it work
,
Answer by tormentoarmagedoom · Apr 07, 2020 at 10:29 AM
Hello.
You should use the LookAt() functiion:
https://docs.unity3d.com/ScriptReference/Transform.LookAt.html
If the object "face" is not the same as the mesh "face" (So look at will be always wrong) you should create a emptyobject and place your object inside (with your "face" looking at the same direction as the blue arrow of this new GameObject) and use LookAt to the whole new GamObject.
Bye"