Comments and answers for "Help clamping a Rotation"
http://answers.unity.com/questions/692372/help-clamping-a-rotation.html
The latest comments and answers for the question "Help clamping a Rotation"Comment by xortrox on xortrox's answer
http://answers.unity.com/comments/694121/view.html
I just remember running into troubles with it before, can't truly remember how or why.Thu, 24 Apr 2014 22:13:23 GMTxortroxComment by ToxxicSin on ToxxicSin's answer
http://answers.unity.com/comments/694113/view.html
But if you're "getting" 315, it should still work if it's set to the minimum, shouldn't it?Thu, 24 Apr 2014 21:59:17 GMTToxxicSinComment by xortrox on xortrox's answer
http://answers.unity.com/comments/693173/view.html
The problem occurs when you try to "get" the euler angles because transform.eulerAngles never contain a value that is negative so -45 becomes 315Wed, 23 Apr 2014 18:43:12 GMTxortroxComment by ToxxicSin on ToxxicSin's answer
http://answers.unity.com/comments/693171/view.html
If 315 is the minimum, I thought the angle would be -45 to 45.
If 315 was the maximum then your explanation would make sense, but I was unaware it would still interpret it like that.Wed, 23 Apr 2014 18:41:41 GMTToxxicSinComment by xortrox
http://answers.unity.com/comments/693041/view.html
I could help you if you got $$anonymous$$mviewer.Wed, 23 Apr 2014 15:19:06 GMTxortroxComment by xortrox on xortrox's answer
http://answers.unity.com/comments/693032/view.html
Behold my glorious illustration,
![Glorious][1]
In this example the 315 to 45 rotation involves a much larger range than my 0 to 90 degrees rotation, yet you would probably expect -45 to 45 to be the same as the 0 to 90 rotation, this is how euler angles would interpret it
[1]: /storage/temp/25629-glorious.pngWed, 23 Apr 2014 15:13:46 GMTxortroxComment by xortrox on xortrox's answer
http://answers.unity.com/comments/693023/view.html
Try your code with clamping -45 to 45 do a quick setup in unity you'll notice it probably wont work and most likely only uses 0-45 degrees as euler angles dont go below 0 degrees
You can however control the angle yourself and have a "starting" rotation like this:
float angleOffset = 0.0f;
float startAngle = 0.0f;
void Update()
{
angleOffset += Input.GetAxis("$$anonymous$$ouse X");
$$anonymous$$athf.Clamp(angleOffset,-45,45);
Vector3 v = transform.eulerAngles;
v.x = angleOffset;
//or v.x = $$anonymous$$athf.Lerp(v.x, angleOffset, Time.deltaTime);
transform.eulerAngles = v;
}
I'm not sure if this would work well at allWed, 23 Apr 2014 15:06:28 GMTxortroxComment by ToxxicSin on ToxxicSin's answer
http://answers.unity.com/comments/692991/view.html
@xortrox Can't you do a minimum of 315 and a maximum of 45?Wed, 23 Apr 2014 14:30:34 GMTToxxicSinComment by xortrox on xortrox's answer
http://answers.unity.com/comments/692968/view.html
Clamping euler angles from -45 to 45 will get troublesome because euler angles are simply horrible in comparison to quaternions when it comes to clamping, you most likely have to make sure your rotation never exceeds 360 degrees or goes below 0 to clamp a euler angle.Wed, 23 Apr 2014 13:46:31 GMTxortroxAnswer by ToxxicSin
http://answers.unity.com/answers/692660/view.html
The simplest way in my opinion is to do Mathf.Clamp.
funtion Update(){
var anglesToEdit : type;
angleToEdit.angle = Mathf.Clamp(angleToEdit.angle), -45, 45);
//the angle you're clamping is probably the .y
//because that is the vertical axis which is used
//to rotate left and right
}
and personally I would clamp the angle between -45 and 45 because your turret more than likely originally spawns with the center facing forward at 0Wed, 23 Apr 2014 03:39:48 GMTToxxicSinComment by xortrox
http://answers.unity.com/comments/692509/view.html
You may want to make sure that the initial angle can go from 0 to 90 in your case without the euler angles exceeding above 360 or under 0, then you could use [$$anonymous$$athf.Clamp][1]:
angle = spinAmount;
transform.Rotate(angle,0,0);
Vector3 cannonAngles = transform.eulerAngles;
cannonAngle.x = $$anonymous$$athf.Clamp(cannonAngle.x, 0, 90);
transform.eulerAngles = cannonAngles;
This is only one of many ways to do it, you could also be using Quaternions
[1]: http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$athf.Clamp.htmlTue, 22 Apr 2014 22:05:14 GMTxortroxComment by murkertrer
http://answers.unity.com/comments/692464/view.html
Hi xortrox, thanks for your interest:)
Is is actually an empty object that i have it attached to my character ( a simple sphere) from where im generating the cannonballs.i figure this would make things simpler and more efective.Tue, 22 Apr 2014 20:50:11 GMTmurkertrerComment by xortrox
http://answers.unity.com/comments/692422/view.html
Can I see what the turret looks like in-game? Is the whole thing rotating or just the turret head etc?Tue, 22 Apr 2014 20:03:56 GMTxortrox