But I don't want to apply a force. I want instantaneous acceleration.
non realistic platformer movement
Games and ApplicationsUse 'ApplyImpulse' then (on b2Body). I just read another post where the poster uses 'SetLinearVelocity()', and I suppose you could try that as well.
The problem is that I want them to move as long as the key is pressed.
If I apply impulse every frame the key is down, they'll accelerate.
If I apply impulse only when they first press the key, they'll stop as soon as they reach an obstacle, and won't start moving again, even if the obstacle disappears.
If I apply impulse every frame the key is down, they'll accelerate.
If I apply impulse only when they first press the key, they'll stop as soon as they reach an obstacle, and won't start moving again, even if the obstacle disappears.
I think there is a 'is_repeat' boolean (or some such) you can play around with in the eventhandlers.
If I got this from somewhere else, you could set that up manually by something like this (pseudo):
That should make sure that the force is only applied once for each key press, when combined with:
Also, if you haven't checked it out yet, the manual is very, very good.
If I got this from somewhere else, you could set that up manually by something like this (pseudo):
Code:
Eventhandler: KeyDown:
if 'isDown' == false
body.ApplyImpulse()
[...]
Set 'isDown' = true
if 'isDown' == false
body.ApplyImpulse()
[...]
Set 'isDown' = true
That should make sure that the force is only applied once for each key press, when combined with:
Code:
EventHandler: KeyUp:
set 'isDown' = false
(possibly set body's velocity to (0,0))
set 'isDown' = false
(possibly set body's velocity to (0,0))
Also, if you haven't checked it out yet, the manual is very, very good.
Storyyeller wrote:
If I apply impulse only when they first press the key, they'll stop as soon as they reach an obstacle, and won't start moving again, even if the obstacle disappears.
hm. Yeah, I can see that happening.
MAybe you should go about it another way then. Every frame, check if the player is pressing the key, if so, check the actor's speed. If the velocity is below whatever you want, then adjust it accordingly.
MAybe you should go about it another way then. Every frame, check if the player is pressing the key, if so, check the actor's speed. If the velocity is below whatever you want, then adjust it accordingly.
Original thread: https://box2d.org/forum/viewtopic.php?t=4164