- Home /
Space.World in MoveObject.js
Hi, I draw the shortest straw and now I am the one in our team who have to code a prototype for a new game idea at university.^^ I have only very little experience with programming overall.
I found the script MoveObject.js on http://www.unifycommunity.com/wiki/index.php?title=MoveObject and use it to rotate GameObjects over time. They rotate around their local axes but I want them to rotate around the world axes. I cant figure out where I have to add Space.World in the script.
I guess it must be in somewhere in this part, but I dont know where.
function Rotation (thisTransform : Transform, degrees : Vector3, time : float) {
var startRotation = thisTransform.rotation;
var endRotation = thisTransform.rotation * Quaternion.Euler(degrees);
var rate = 1.0/time;
var t = 0.0;
while (t < 1.0) {
t += Time.deltaTime * rate;
thisTransform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
yield;
}
}
Thanks for help.
Answer by Eric5h5 · Sep 23, 2011 at 08:35 PM
You can try substituting this code, while keeping the rest of it the same:
var startRotation = thisTransform.rotation;
thisTransform.Rotate(degrees, Space.World);
var endRotation = thisTransform.rotation;
Answer by RoughDesign · Sep 23, 2011 at 05:26 PM
Welcome here dondiego,
You are rotating a transform over time by assigning new values to the variable transform.rotation over time.
However, Unity has a built-in function for that, transform.Rotate.
This function is where you can use Space.World and it will also let you achieve what you want there with less code.
With transform.Rotate is the roration instant. I would like to smoothly rotate the object about 90 degrees within one second. How can I achieve that with transform.Rotate?
transform.Rotate is in no way a substitute, nor would it result in less code. The point of the function is to have specific start and end rotations, and lerp between them over time, which cannot be done using Rotate.
Your answer
Follow this Question
Related Questions
Rotating sphere with rigidbody attached 1 Answer
Armature Rotation, lookAt on y axis, not z axis. 0 Answers
Random Rotation all 3 Axes 2 Answers
Using an Xbox 360 controller for Rotation 0 Answers
Head bone rotation question 0 Answers