- Home /
Rotate an Object by a spezific value
I want to turn an Object by lets say 10 degrees on the Y-Axis.
I wrote: transform.rotation.y+=10;
I thought that would be the most logic. But the Object turns itself by a incredible... ehh... little value: -5.008956e-06
Can anybody explain that?
Thanks for your attention =)
Try this way to see if it has the same results.
transform.rotation.y = transform.rotation.y + 10;
Ok, well my answer should come out and it will work. Just has to wait to be approved by mod so give it some time.
Well in the case the mod doesn't approve $$anonymous$$e I am going to put it here.
Use this line of code:
transform.Rotate(Vector3.up * 10); It will increase by 10 to decrease you do this.
transform.Rotate(-Vector3.up * 10); This will decrease by 10. On the y axis.
Answer by Matthew0123 · Jan 20, 2013 at 10:05 PM
Alright, since I really hate doing it that way (and it is not working for me either, but I never rotate this way).
I use this and it works perfectly for me. It will add 10 every time it is called
var rotateSpeed : float;
rotateSpeed = 10;
function Update () {
transform.Rotate(Vector3.up * rotateSpeed);
}
Thanks! it works =D
but now i got the problem that I cannot set the rotation to a value...
transform.rotation.y=Cannon.transform.rotation.y doesnt work. (of course I wrote var Cannon:Transform at the beginning)
Well there is a roundabout way you can do this with 3 more vars. You will just have to add this and edit it at your own will.
var initalAngle: float; var deltaAngle: float; var offset: float;
if (initalAngle != angleWanted) { offset = initalAngle - deltaAngle; initalAngle = initalAngle - offset; } that should get you to the angle you want. If it doesn't get you it tell me and give me some variables, like the angle you want it to be and what angle you start at.
well... I use no Variables. I just want a gameObject to look in the same direction as another gameObject.
There is a cannon witch turns itself clockwise until it "sees" the player. well the challenge is here to make the cannon not see through walls or chests or whatever. I slove it... or want to slove it with gameObject`s that move out of the cannons front, and return to the Cannon after some time OR if they collide with an obstacle. Just like a Radar. But the cannon should "look" at the player and shoot until the player nomore comes in contact with the radar-Object`s. And because of this. the Radar Object`s have to look in the direction the Cannon looks every radar-wave.
alright, I got it! =D
the working script: transform.rotation=Cannon.transform.rotation
so simple... Thanks for your efforts! =)
Yeah no problem, if you need help with more basic stuff contact me on skype if you got one. Assassin12211
Also, mark this answer as correct so others can get it if they're looking as well. Thanks.
Answer by robertbu · Jan 23, 2013 at 08:36 AM
Transform.rotation is a Quaternion. According to the reference, "[Quaternions] are based on complex numbers and are not easy to understand intuitively." Thus you almost never access or modify individual Quaternion components (x,y,z,w);
In order to rotate the amount you want, look at Transform.eulerAngles. But you cannot modify eulerAngles directly. Instead you have to do something like:
var v3T : Vector3 = transform.eulerAngles;
v3T.y = v3T.y + 10;
transform.eulerAngles = v3T;
There are a number of other ways to rotate something as well including (as Mathew0123 mentions), using transform.Rotate();
Your answer
Follow this Question
Related Questions
Set Specific List Value 3 Answers
Positions to rotations of a regular GO 2 Answers
Function to rotate my Player smoothly taking the y and use it to have angle 1 Answer
Quaternion.ToAngleAxis is Unprecise? 1 Answer
Temporary Rotation 2 Answers