- Home /
Pointing Object in the Direction it is going
Hi, Basically i have a game object "Hunter" witch fires another object "Dart" in 3 different directions, fires left ,straight and right and repeats endlessly, the problem i am having is to point that "Dart" in the direction it is going.
here is the sample i tried the LookAt and Quaternion.LookRotation with no success any help appreciated.
while (canShoot) { start = _dartInstance.transform.position; _dartInstance.transform.position = Vector3.MoveTowards(start, destination, Speed * Time.deltaTime); //_dartInstance.transform.position = Vector3.Lerp(start, destination, Speed * Time.deltaTime); _dartInstance.transform.LookAt(destination); if (start == destination) { canShoot = false; yield return null; } yield return null; }
So I understand the dart isn't pointing where you want it to, but where does it point? Does it depend on the destination, or always to the same direction?
LookRotation() and LookAt() only work if your model is constructed so that the forward side is pointing at positive 'z' when the rotation is (0,0,0). For 3D the best fix is to change the rotation in the modeling program, though you can use an empty game object as a parent to fix the problem. For 2D, the best fix is alternate code.
yes the dart just doesn't point in the direction it is going. it depends on the direction. so lets say the dart is fired in the +z axis, the dart goes straight then goes -3 in the x and +3 in the x, when it goes -3 or +3 it moves to that point but it doesn't not face that point if you get me.. basically the dart is facing straight when moving left or right
robertbu, at the moment im only using a unity sphere scaled to look like a dart.
Answer by robertbu · Jul 09, 2014 at 03:32 PM
Then you need to scale down the x and y sides so that the dart object points in the positive 'z' direction when the rotation is (0,0,0).