- Home /
Freeze an Axis Rotation Help?
Scene contains flat terrain, and a cube.
I can fly the cube around! (yay)
The cube is realy hard to fly around, unless the Y axis is locked. (Otherwise the cube can turn backwards, and the controls get all crazy!)
So far, Every method of locking the Y axis has had a problem in it.
If you guys can think of another method, that would be fantastic!
Note: Every axis is a Local axis to the Cube.
Heres what I've tried:
Locking Y rotation in the Rigidbody Constraints section
This, strangely, does absolutely nothing.
transform.eulerAngles.y = 0;
This Works, however the cube Cannot go upside-down, and gets stuck at exactly half way
rigidbody.rotation.y = 0.0;
This is the closest I've come to success. Everything in the air works perfectly, however, The cube gets stuck in the ground whenever i touch it, and is no longer under my control.
Thanks for Reading this! Heres some code:
#pragma strict
public var Enginepower : float;
public var TiltPower : float;
public var EnginePlate : GameObject;
public var Particles : GameObject;
function Start () {
EnginePlate = GameObject.Find("EngineOn");
Particles = GameObject.Find("Particles");
}
function Update () {
//******************************************************************************BEGIN PROBLEM CODE AREA *************************************************************************************
//Several lines, Each of which attempt to Lock Y axis Rotation
//transform.eulerAngles.y = 0;
rigidbody.rotation.y = 0.0;
//*******************************************************************************END PROBLEM CODE AREA **************************************************************************************
//Fire the Main Engine Code Block
if(Input.GetButton("Engine1")){
//Add virticle force along the local Y axis
rigidbody.AddRelativeForce(Vector3.up * Time.smoothDeltaTime * Enginepower);
//Activates Rendering of the Engine plate and Particle Effect
if(!EnginePlate.renderer.enabled){
EnginePlate.renderer.enabled = true;
Particles.renderer.enabled = true;
}
}else{
//Hides engine plate and Particles if engine not on
if(EnginePlate.renderer.enabled){
EnginePlate.renderer.enabled = false;
Particles.renderer.enabled = false;
}
}
if(Input.GetButton("BackwardsTilt")){
rigidbody.AddRelativeTorque(-Vector3.right * Time.deltaTime * TiltPower);
}
if(Input.GetButton("ForwardsTilt")){
rigidbody.AddRelativeTorque(Vector3.right * Time.deltaTime * TiltPower);
}
if(Input.GetButton("LeftTilt")){
rigidbody.AddRelativeTorque(Vector3.forward * Time.deltaTime * TiltPower);
}
if(Input.GetButton("RightTilt")){
rigidbody.AddRelativeTorque(-Vector3.forward * Time.deltaTime * TiltPower);
}
}
What is the goal, how do you want it to work? Have you considered fixing the camera behind the cube so that the controls are aleays the same even if it rotates?
Fixing the camera behind the cube works, but the game looks very odd. All i want is for the cubes Y axis to not rotate, so that the front face faces front. Otherwise, (if the cube rotates after something like a ground collision,) You could push the Rotate away from button and the cube would roll sideways. Thanks for your Reply!
Your answer
Follow this Question
Related Questions
Lock Z Rotation. Character Controller. 1 Answer
fixing rotation on a specific axis 1 Answer
Lock the Camera's Y Rotation Axis? 0 Answers
Input axes freeze from opposite input rather than cancel out! 1 Answer
how to lock the z axis rotation 2 Answers