- Home /
Translate Vector3.forward and Raycast Vector3.forward have different directions
Hey guys,
I'm not sure whether I just become crazy or what the problem is. I'm just using this very little and simple script. It's applied on a sphere with a rigidbody and a collider. I want the sphere to move slower as it gets closer to the wall in front. But for some reason the directions are different.
The Raycast is not casted forward! Because the sphere is moving forward but the var distance is constantly 3.5 which describes the distance to the wall on the side of the cube. But it's not supposed to cast the ray forward and not to it's right. But when I use Vector3.forward to move it forward it's moving just as it should be. So it looks like if Vector3.forward in the first place and Vector3.forward in the second place describe different direction. But how is this possible? There is nothing there between that is changing the rotation or something like this!
That's my small and actually very easy function:
function Move ()
{
var hit : RaycastHit;
if(Physics.Raycast(transform.position, Vector3.forward, hit, 100))
{
var distance = Vector3.Distance(transform.position, hit.point);
Debug.Log(distance);
transform.Translate(Vector3.forward * movementSpeed * distance/50 * Time.deltaTime);
}
}
I have no idea what I am doing wrong! And it's actually not my first time working with Unity3D... Can you help me please?
Vector3.forward is world forward. If you want an object's forward then use transform.forward ins$$anonymous$$d.
Your answer
![](https://koobas.hobune.stream/wayback/20220611231958im_/https://answers.unity.com/themes/thub/images/avi.jpg)