Adding/Changing a Gear's Velocity- Lua

4 replies [Last post]
yellowcrash10
yellowcrash10's picture
User offline. Last seen 6 years 47 weeks ago. Offline
Joined: 2012-01-14
Posts: 20

Hmm. I'm trying to create a gear (in this case a grenade) that moves as if it was thrown, but it doesn't move no matter how high you set the values. I also did a test with one of the hedgehogs, and it just moved up a little and stopped. here's the code I have now:

Quote:
--Reference: AddGear(x, y, gearType, state, dx, dy, timer)
AddGear(x, y, gtAmmo_Grenade, 0, 100, 100, 0)

Aww, man!

yellowcrash10
yellowcrash10's picture
User offline. Last seen 6 years 47 weeks ago. Offline
Joined: 2012-01-14
Posts: 20

Never mind! I figured it out! I guess you need to change the values to unimaginably high levels.

Aww, man!

nemo
nemo's picture
User offline. Last seen 21 weeks 1 day ago. Offline
Joined: 2009-01-28
Posts: 1861

By "unimaginably high" you might mean "velocities similar to those I could have retrieved with the getters when logging a typical grenade throw" ? Smile

Due to floating point issues between platforms, we stick to integer only in lua. The values for velocity are arbitrary anyway.
If we were using the in-game value for "100" you should not even see the grenade, it should vanish immediately due to having left the playing area in a 50th of a second. The Lua dx/dy are game values times a million. Sane Lua values should be less than a million usually.

BTW, this means if you want to do division and don't want to risk desyncing clients, you need to use the div() routine in 0.9.18.

Prior to 0.9.18, just avoid doing division.

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

yellowcrash10
yellowcrash10's picture
User offline. Last seen 6 years 47 weeks ago. Offline
Joined: 2012-01-14
Posts: 20

nemo allegedly wrote:

By "unimaginably high" you might mean "velocities similar to those I could have retrieved with the getters when logging a typical grenade throw" ? Smile

Due to floating point issues between platforms, we stick to integer only in lua. The values for velocity are arbitrary anyway.
If we were using the in-game value for "100" you should not even see the grenade, it should vanish immediately due to having left the playing area in a 50th of a second. The Lua dx/dy are game values times a million. Sane Lua values should be less than a million usually.

BTW, this means if you want to do division and don't want to risk desyncing clients, you need to use the div() routine in 0.9.18.

Prior to 0.9.18, just avoid doing division.

Thanks! It would have helped to know that a long time ago Big Grin
Just to make the grenade even MOVE, I had to use the following code (I set x, y to their values before this: )

Quote:
AddGear(x, y, gtAmmo_Grenade, 0, 400000, 100000, 0)

lol?

Aww, man!

nemo
nemo's picture
User offline. Last seen 21 weeks 1 day ago. Offline
Joined: 2009-01-28
Posts: 1861

yellowcrash10 allegedly wrote:

nemo allegedly wrote:

By "unimaginably high" you might mean "velocities similar to those I could have retrieved with the getters when logging a typical grenade throw" ? Smile

Due to floating point issues between platforms, we stick to integer only in lua. The values for velocity are arbitrary anyway.
If we were using the in-game value for "100" you should not even see the grenade, it should vanish immediately due to having left the playing area in a 50th of a second. The Lua dx/dy are game values times a million. Sane Lua values should be less than a million usually.

BTW, this means if you want to do division and don't want to risk desyncing clients, you need to use the div() routine in 0.9.18.

Prior to 0.9.18, just avoid doing division.

Thanks! It would have helped to know that a long time ago Big Grin
Just to make the grenade even MOVE, I had to use the following code (I set x, y to their values before this: )

Quote:
AddGear(x, y, gtAmmo_Grenade, 0, 400000, 100000, 0)

lol?

Eh. Smaller values would also make it move, it depends entirely on the environment.
Friction, gravity...
If gravity is being neutralised each game tick, or set very very low at start, smaller values would cause it to drift lazily.
Would behave differently on ice, too.

100,000 is actually a rather high speed.

Oh, BTW, the exception to the integer only rule is visual gears, which don't impact game state. That also means you shouldn't use values from a visual gear to do game stuff.

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

User login

Copyright © 2004-2024 Hedgewars Project. All rights reserved. [ contact ]