I need to move an object forward a specific distance from a start point in space. The start point does not have a forward vector, so I need to compute one from the start point to (0,0,0).
I can successfully compute a new start point with the correct forward vector, however when I use it to move an object it multiplies the move distance instead of adding it.
// "start" is actually a raycast hit point, but am using a Vector3 here for simplicity float moveDistance = 2; Vector3 start = new Vector3 (0, 0, 3); Vector3 center = new Vector3 (0, 0, 0); Vector3 fwd = start - center; myObject.position = start + fwd * moveDistance; Debug.Log (fwd); //returns: (0.0, 0.0, 0.3) Debug.Log (myObject.position); //returns: (0.0, 0.0, 9.0)
The result is myObject.position = 0, 0, 9 // multiplying moveDistance
And the desired result is = 0, 0, 5 // adding moveDistance
The result does have a forward vector, but it's multiplying instead of adding distance. When I do the same calculation for myObject.position using the forward vector of a gameobject, it adds the distance.