How do you make an enemy fly or float along horizontally (for a side scroller), with gravity turned on?
Basically, I need to have gravity for this game, and also need the enemy to be “dynamic”. I know that setting the enemy to kinematic, it will avoid gravity thus I can use “setLinearVelocity” to move it. BUT, if I make my enemy “dynamic”, even setting it’s “setLinearVelocity” will NOT make it fly or float. My first solution was to create a runtime event listener and run a function to keep the enemy / object up in the air. But this solution is giving me issues (specifically memory leak issues), especially when I put it within a for loop for creating multiple enemies.
My question is, is there another or more efficient way to make “dynamic” objects “fly” or “float” horizontally (on the x-axis)? I hoped there would be a way to disable gravity for just an object, but I’ve already tried and also read a few threads that say, nope…
Here’s psuedo code for what I tried to do (which doesn’t seem to be the most efficient way IMO):
- set GRAVITY to (0,10)
- set “setLinearVelocity” of the object / enemy to (0,-10) - this will make your object go to the left
- put the “setLinearVelocity” into a function, that is triggered by a runtime event listener
Any suggestions, links to other threads, or help?
THANKS [import]uid: 129334 topic_id: 24222 reply_id: 324222[/import]
[import]uid: 52491 topic_id: 24222 reply_id: 97891[/import]