- Home /
Question by
balakademi · Jun 21, 2013 at 09:24 AM ·
rigidbodypositionai
insead of Position == Position ?
my problem is "this.transform.position != hedefinKonumu" not working. Because my rigidbody object not going to that exact position. going to near and rotating around.
How can i solve this?
public void GezinDolasin ()
{
if (!konumBelirlendi)
{
hedefinKonumu = new Vector3(Random.Range(-7, 7), Random.Range(-4, 4), 0); // Random.Range(-3, 3)
konumBelirlendi = true;
}
if (this.transform.position != hedefinKonumu)
{
// Hedefe Don
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(hedefinKonumu - this.transform.position), donusHizi * Time.deltaTime);
// Hedefe Git
this.transform.position += this.transform.forward * hareketHizi * Time.deltaTime;
}
else
{
konumBelirlendi = false;
}
}
Comment
Best Answer
Answer by whydoidoit · Jun 21, 2013 at 09:26 AM
So normally you will check for a distance like this:
if((transform.position - hedefinKonumu).sqrMagnitude < 0.1f) //Or something similarly small
You use sqrMagnitude because it doesn't require an expensive square root.