Scripts / What is wrong with the timer?

Author
Message
Mariokiki
16
Years of Service
User Offline
Joined: 22nd Oct 2008
Location:
Posted: 1st Apr 2015 12:18
I tried to make a script to rotate an entity onto itself (Y axis) using the timer to always have constant speed rotation.

Unfortunately, this doesn't work, and the entity begins to spin faster and faster !


----------------------------------------------
local delay = {}
local init_delay = {}
local rotation = {}

GravityOff(e)

function rotation_objet_init(e)
delay[e] = 25
init_delay[e] = delay[e]
rotation = 0
end

function rotation_objet_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 500 then
if GetTimer(e) > delay[e] then
delay[e] = GetTimer(e) + init_delay[e]
RotateY(e,rotation)
rotation = rotation + 1
end
Prompt(rotation)
else
RotateY(e,0)
rotation = 0
end
end
-----------------------------------------------------

Please help me for this script!
Thank you !

Attachments

Login to view attachments
PM
Mariokiki
16
Years of Service
User Offline
Joined: 22nd Oct 2008
Location:
Posted: 1st Apr 2015 13:35
Fixed !

Using "SetRotation(e,0,rotation,0)" instead of "RotateY(e,rotation)"

If someone know what's the difference ?

Thank you... ME !
PM
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 1st Apr 2015 13:36
First mistake:
local rotation = {} is an array but you use it as variable rotation = 0
second mistake:
You never start the entity timer with StartTimer(e)

You did more what I not really find good, but if it works


My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 1st Apr 2015 13:38
SetRotation(e,0,rotation,0) Set the angle which the entity looks
RotateY(e,rotation) rotates the entity with the speed of rotation
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 1st Apr 2015 17:26
should have just used rotation = 1 instead of increasing it each time because as corno says it's a speed type setting.
setrotation(e,x,y,z) however uses the 0~360 degrees angle

Quote: "You never start the entity timer with StartTimer(e)"

you dont need to, all timers start by default anyway, only reason to start a timer is to know it's value will be 0
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Mariokiki
16
Years of Service
User Offline
Joined: 22nd Oct 2008
Location:
Posted: 1st Apr 2015 20:56
Thank you guys for the clarification.
Using "RotateY(e,rotation)" it was normal that the speed increases! I understand why now.

But I can remove the "local rotation = {}" on top of the script because it's a variable, not a array...

I use DBPro since long time... I'm fine to get to use the scripts properly !

Fortunately you are there to give advices !

Many THANKS !
PM

Login to post a reply

Server time is: 2024-12-21 13:44:09
Your offset time is: 2024-12-21 13:44:09