- Home /
Urgent! Rotation question!
Hello, I am a new solo developer using unity. I am trying to make it so that my character cannot twist around 360 degrees. I want it so that the character can only look 180 degrees (from left to right). Here is a run-down of what I have done with my character:
-Added the mouse look script to all the parts of the character I want to move. The specifics I have put in all of them are:
min x: -10
max x: 10
min y: -10
max y: 10
-Taken all the first person controller scripts and added them to my character model
-Taken the main camera from the first person controller and added it to my caharacter model
-Positioned the main camera in the characters head, as if it were eyes.
Please help!!! Thanks.
Answer by koichisenada · Jan 07, 2013 at 09:07 AM
I suppose you're turning your character by the mentioned "mouse look script", so that is the script you should tweak to introduce the rotation borders.
I tried that, but the character just spins 360 anyway? Ideas?
It depends on the way you're tweaking your script. Suppose, your code detects that current angle is 178 degrees and your mouse input offers additional 4 degrees, but before applying it your code would check the result and find that 182 degrees are more than the boundary limit of 180 degrees, so it just puts the value of 180 degrees.
float angle = this.GetCurrentAngle();
float angleNew = angle + this.GetAdditionalAngle();
if (angleNew>180) { angle = 180; } else { angle = angleNew; }
Your answer
Follow this Question
Related Questions
why is the mouse look messing up on the new fps character 0 Answers
Heya again guys how about rotation and score board 0 Answers
Making a continuous shooting sound while the fire button is held down. 1 Answer
Can't stop camera from rotating on Z Axis 1 Answer
How can I make player rotation control camera's x rotation and mouse control it's y rotation? 1 Answer