- Home /
Rotation accuracy in build
I'm having an issue keeping my object rotating in 90 degree increments when I build and run my game. However it seems to work fine in the editor and I know this should be working
Any help would be greatly appreciated. Here's the code i'm currently using
var Player : Transform; var rotateAmount = 90; var rotateTime = float;
function Update () { if ( Input.GetKeyDown("z")) // point, axis, amount, time RotateObject(Player.position,Vector3.forward, 90,1.0);
if (Input.GetKeyDown("x"))
RotateObject(Player.position,Vector3.back, 90,1.0);
if (Input.GetKeyDown("c"))
RotateObject(Player.position,Vector3.left, 90,1.0);
if (Input.GetKeyDown("v"))
RotateObject(Player.position,Vector3.right, 90,1.0);
}
function RotateObject(point : Vector3, axis : Vector3, rotateAmount : float, rotateTime : float) { var step : float = 0.0; //non-smoothed var rate : float = 1.0/rotateTime; //amount to increase non-smooth step by var smoothStep : float = 0.0; //smooth step this time var lastStep : float = 0.0; //smooth step last time while(step < 1.0) { // until we're done step += Time.deltaTime rate; //increase the step smoothStep = Mathf.SmoothStep(0.0, 1.0, step); //get the smooth step transform.RotateAround(point, axis, rotateAmount (smoothStep - lastStep)); lastStep = smoothStep; //store the smooth step yield; } //finish any left-over if(step > 1.0) transform.RotateAround(point, axis, rotateAmount * (1.0 - lastStep)); }
Answer by Eric5h5 · Apr 13, 2011 at 12:17 AM
"var rotateTime = float
" is incorrect syntax and won't work. Anyway, it looks like the main issue is that you have nothing to prevent rotating while a rotation is already in progress. Either rewrite the Update function as a coroutine and yield on the RotateObject routine, so input isn't checked while it's running and therefore unwanted rotations are impossible, or have some kind of variable that's set true when rotating and false when not, and don't allow the routine to run if the variable is true.
It doesn't seem to be working. The problem is my rotation is co$$anonymous$$g up to short. I want it to be a 90 degree rotation but it seems to only do about half of that. Any ideas?
The RotateObject function seems to be based on time. I guess you'd want to rewrite that so it's based on degrees rotated ins$$anonymous$$d.
I hate to be a bother but you wouldn't happen to know how to do that would you? or at least have an idea on where I could look perhaps? I've been racking my brain trying to get it to work correctly and to be honest I'm a noob at javascript
@$$anonymous$$$$anonymous$$7: See the Rotation function here: http://www.unifycommunity.com/wiki/index.php?title=$$anonymous$$oveObject
Your answer
![](https://koobas.hobune.stream/wayback/20220613122353im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
mecanim run animation script trouble 0 Answers
Running batch script or .exe after "build&run" 1 Answer
Distribute terrain in zones 3 Answers
OnTriggerEnter2D Rapid Fire 0 Answers
9 errors in Javascript 1 Answer