Page 1 of 1

Is there a better way to add gravity to my game?

Posted: Fri Jun 02, 2023 6:25 am
by silvr64official
In my games that I made myself, I add code that basically changes the objects y velocity by the games gravity variable which’s adds the y velocity to the y position of the object (unless the object is touching another object then it’s y velocity resets to zero which I have trouble figuring out :cry: )

Is there a better or at least easier solution to that?

Re: Is there a better way to add gravity to my game?

Posted: Fri Jun 02, 2023 11:48 am
by Andlac028
If you want easier solution than implementing whole physics, you can take a look at love.physics module

Re: Is there a better way to add gravity to my game?

Posted: Fri Jun 02, 2023 11:53 am
by BrotSagtMist
Thats already a three lines solution. Hard to make it any easier.
Where is it troubling you?

Re: Is there a better way to add gravity to my game?

Posted: Fri Jun 02, 2023 2:13 pm
by togFox
You can google my Mars Lander on itch.io that has gravity and thrust and all those fun things. You'll probably be confused by that code. I know I am. 8-)

Love.physics is a full blown physics engine that takes some practice.

Sounds like you need to do some sort of bounding box type detection otherwise just apply downwards gravity * dt every cycle.