|
I feel stupid asking this, but i'm not sure how its done. I would like an object to rotate 180 degrees on it's x axis after waiting 3 seconds, and then repeat. But when I use this script, it just waits three seconds on load time, then continues spinning forever. Sorry for this stupid question I guess I want the spin function to loop, but I don't know how.
(comments are locked)
|
|
That's the old fashioned way to do this: I'm sure yield could be a better alternative, but I just can't understand this %#@! thing! Oh, I forgot to initialize tCycle to zero at the beginning. I think the system does that, but Murphy's Laws are implacable...
Jun 11 '11 at 07:01 PM
aldonaletto
thank you very much. could you explain the first if statment that ended with ;? how does that work. The script works by the way
Jun 11 '11 at 07:03 PM
Eli Davis
tCycle always indicate the end of a 3 seconds cycle. Whenever Time.time is higher than tCycle, tCycle is reloaded with Time.time plus 3 seconds. Be aware that after some time the object may drift a little, stopping at a slight different angle due to errors accumulated at each cycle. If it happens, call for help here and we'll try to find some way to fix it.
Jun 11 '11 at 07:19 PM
aldonaletto
Yes, the more the game lags, the more it seems to get the angle wrong, I'm not completely sure how to fix this, but an idea is to set the rotation to 0, 0, 0 after a certain amount of turns or idk. Something like that? Also, could I put this on my blog? I'l reference people to your profile for credit.
Jun 11 '11 at 10:21 PM
Eli Davis
I just can't edit my answer! Damn new UA! if (t>tCycle){ It forces the object to the ideal angle at the beginning of each cycle.
Jun 11 '11 at 11:06 PM
aldonaletto
(comments are locked)
|
|
If I understand the question, what you want is to have the object finish a rotation of 180 degrees every 3 seconds? What your code is doing now is initially waiting for 1 second (your yield statement), and then spinning 180 degrees per second after that. I think what you want would look something like this. What's happening here is that your rotating the object 60 degrees per second (which is the same thing as saying 180 degrees every 3 seconds). Hope that's what you were looking for! -Kith I'm sorry I worded the question wrong, I re worded it now. but thank you for your answer, you awnsered it correctly wrong worded question
Jun 11 '11 at 06:59 PM
Eli Davis
No worries lol. Aldonaletto's answer should work fine for what you're trying to do then.
Jun 11 '11 at 07:23 PM
Kith
(comments are locked)
|
