- Home /
I could not be more lost (rotation script)
I am trying to make a script that would rotate a cylinder on button push but still restrict movement. I basically want it to move from 0 to 90 degrees freely but stop it from moving any farther.
The real problem is i am trying to do the exact same thing with another cylinder with different keys in a different direction(270 - 360).
Oh, the problems I've had. I have tried so many things to fix my problem, i don't even no what problem is what anymore.
so after 2 hours of sheer frustration i decided to ask for some help.
if(direction == 1){//dont worry about this
if((Input.GetKey(keys[0])||Input.GetKey(keys[2]) && transform.rotation.eulerAngles.x < 340)){// if figure that restraining it a 340(close enough to 360)
// will stop it from annoyingly switching back over to zero rotation
transform.Rotate(4,0,0);
}
if( (Input.GetKey(keys[1]) ||Input.GetKey(keys[3])) && transform.rotation.eulerAngles.x > 270){
//by the way keys[] is an array that holds string values, that all works great
transform.Rotate(-4,0,0);
}
}else{
//again don't worry about the else, t just separates the cylinders from each other, so i know which way to move it
if((Input.GetKey(keys[0])||Input.GetKey(keys[2]) )&& transform.rotation.eulerAngles.x < 90){// this would be the other cylinder
transform.Rotate(4,0,0);
}
if( (Input.GetKey(keys[1]) ||Input.GetKey(keys[3])) &&transform.rotation.eulerAngles.x >5 ){
transform.Rotate(-4,0,0);
}
}
Just incase i forgot to mention, the problem is that the cylinder fails to stop moving. thank you for your time
have a Quishtay™ Day
I suggest simplifying things to start with.
First get it working with one object.
Then look at refactoring the movement code into a separate function that can be applied to each object.