- Home /
Question by
thomasmahler · Dec 30, 2014 at 09:26 PM ·
raycastracing gamealign
Kart Racer - Align Kart to hit.normal on X and Z, but not Y
Hey guys,
I'm trying to make a quick Kart game prototype, but I can't figure out how to properly align the kart with the ground.
Here's what I have so far:
http://www.warsoup.com/RacingGame/RacingGameWeb.html
I'm using this code here to adjust the y rotation based on the Analog Stick Input:
if(currentSpeed > 1 || currentSpeed < -0.2)
{
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed * Time.deltaTime;
transform.Rotate (0, rotation, 0);
}
So, I need to be able to always control the Y rotation of the object, simply cause I'm using this code here to accelerate:
transform.Translate(Vector3.forward * currentSpeed * Time.deltaTime);
Now, all the suggestions here are saying that I should simply use this code to adjust the rotation to the hit.normal, but it overrides the Y rotation, so I can't steer anymore if I use it:
transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
Is there any smart way to adjust the rotation of my object to the hit.normal in X and Z, but not in Y?
Comment