in the car tutorial how can i change the forward vector for the car ? the complete scene setup the forward is pointing 45' degree to the track street i want the forward for the car to point always to the front of the car
If i used the above code into the tutorial car it always look at 45' degree it doesnt look straight to the track road.
Sounds like your car has been modelled in your 3d modelling app with its origin (pivot) pointing in the wrong direction.
This is best fixed in the 3d app itself, although you can work around it by parenting your car model to an empty 3d game object. Then you can treat the empty game object as if it were the car (i.e. place scripts on it), and have the incorrectly aligned car model as a child, rotated to face the correct way.
After the transform.LookAt, you shut put:
transform.Rotate(new Vector3(/*experiment here until it works*/));
No redoing 3D model, no parenting to empty, just a line of code.
How i tend to get around this fairly easily is by putting my model in its own gameObject. I then child that game object to another transform which contains the movement scripts. Meaning I can rotate and change the position of my model any time without effecting the movement direction.
LookAt takes a transform or position as an argument, not a direction. The direction vector passed with transform.forward is going to be the normalized direction of wherever the cars z axis is pointing, but the cars z axis will lookat the world origin (0,0,0) + the normalized direction vector which may be 1,0,0 for example. So it will look at 1,0,0 in world space… The proper use of LookAt in this case would be: LookAt(carsPosition + carTransform.forward) … That is assuming that the car model’s z axis points toward the front of the car, if it’s not pointing to the front of the car than choose the direction that is (the red right direction vector for example) and use that instead…
Neither of these responses was appropriate for my situation (which involved an auto-follow camera following from the wrong side) - I ended up just sticking a cube inside my backward model (optionally disabling the mesh renderer) and making THAT the target for my camera