|
Hi ! I've encountered an error when changing rotation into Rotate in front of euler angles it works , but I'd like to make it rotate slowly like using Rotate instead of rotation , how should I do ?
(comments are locked)
|
|
I had no time to test this, but I think it does exactly what you're trying to do - replace your script with this one and tell me if you have any problem:
var Statue : GameObject;
private var rotating = false;
function OnTriggerEnter(other : Collider){
if (other.gameObject.tag == "Boite"){
RotateY(Statue.transform, 90, 1.1); // rotate gradually 90 around Y
}
}
function RotateY(transf: Transform, angle: float, time: float){
if (rotating) return; // ignore other calls while rotating
rotating = true; // flag to indicate "I'm rotating already"
var t: float = 0;
var euler = transf.eulerAngles;
var init = euler.y;
var end = init + angle;
while (t < 1){ // t will vary from 0 to 1 in time seconds
t += Time.deltaTime / time;
euler.y = Mathf.Lerp(init, end, t); // define Y angle proportional to t
transf.eulerAngles = euler;
yield; // return here in the next frame
}
rotating = false; // finished rotating
}
Thank you so much aldonaletto , it couldn't work better ! If you need 3D Modeling help , tell me here : DanaoPolice(at)hotmail.fr , I would be glad to help you in return with what I know doing ;)
Jul 29 '11 at 03:04 PM
Anykey
Thanks for your offer - be sure I'll cry for help if I need!
Jul 29 '11 at 05:05 PM
aldonaletto
(comments are locked)
|
|
Use this. http://unity3d.com/support/documentation/ScriptReference/Vector3.RotateTowards.html Or if you're into quaternions, you can use http://unity3d.com/support/documentation/ScriptReference/Quaternion.RotateTowards.html Thanks for replying var speedmin : float = 2; var speedmax : float = 4; var from = new Vector3(0,0,0); var to = new Vector3(0,90,0); Statue.transform.position = new Vector3.RotateTowards(from, to, speedmin, speedmax); it still doesn't work though, I've got this error message: Assets/MesAssets/MesScripts/TriggerStatueRotation.js(32,41): BCE0017: The best overload for the method 'UnityEngine.Vector3.RotateTowards(UnityEngine.Vector3, UnityEngine.Vector3, float, float)' is not compatible with the argument list '(UnityEngine.Transform, UnityEngine.Transform, float, float)'.
Jul 27 '11 at 08:33 PM
Anykey
Read the error. It says you are trying to feed Transforms into a function expecting Vector3s. The way RotateTowards works is you feed it two vectors: one that is where the object is pointing, and another which is where you want it to point. The result is a vector that has moved partway toward pointing the way you want it to when it's done.
Jul 27 '11 at 08:40 PM
almo
No more error , but the Statue GameObject is rotating to 3.9999 , not to 180 private var startPosition : Vector3; var from : Vector3; var to : Vector3; var speedmin : float = 50; var speedmax : float = 180; function Start (){ } from = startPosition; to = Vector3(0,180,0); Statue.transform.eulerAngles = Vector3.RotateTowards(from, to, speedmin, speedmax);
Jul 27 '11 at 09:17 PM
Anykey
You don't use RotateTowards with EulerAngles. Reread my comment. It takes a vector, and returns a vector that has been rotated to be closer to pointing toward the second vector.
Jul 27 '11 at 09:19 PM
almo
I'll try on tommorow , Statue.transform.eulerAngles = Vector3.RotateTowards(from, to, speedmin, speedmax); I've tried rotation , localRotation , Rotate instead of eulerAngles , but nothing work because they are all quaternions , I really don't know what to use
Jul 27 '11 at 09:36 PM
Anykey
(comments are locked)
|
