Why are objects not accurately finding another object's center?
I have this script that is supposed to make one object (Enemy) go to another object (Player)'s position, and I would assume that this would result in their centers meeting, but I keep having this issue where they go to Player's edge instead.
Here's the rotation script I'm using:
lookPos = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(lookPos);
transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime);
I had the same problem with transform.lookAt();
Neither object is a child.
Also this is my first post so I might've done something wrong
Thanks
The Enemies are triangular pyramids I made with ProBuilder, by taking a cube and shrinking one face down.
Answer by NoicePlayer · May 03, 2021 at 02:45 AM
It turns our the problem was that the pivot point was not the same as the center point, as ProBuilder automatically puts the pivot on a vertex instead. So I remade the object and moved the pivot to the center and now everything works as intended.
Thank you for answering though! :)
Answer by ShadoX · May 01, 2021 at 12:02 PM
A wild guess is that your GameObject's center isn't actually where you expect it to be.
For example - When you select the "Move tool" that shows you the 3 axis on a selected GameObject. Does it appear at the center of the object, like you would expect or is it somewhere "off center" ?
Alternatively - is this GameObject a child of another gameobject, which you are moving instead ? In that case it could be that the center of the child object doesn't align with the parents center.