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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
silvr64official
Prole
Posts: 1
Joined: Thu Jun 01, 2023 11:42 am

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

Post 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?
Where's the kaboom, theres supposed to be an earth shattering kaboom?
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

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

Post by Andlac028 »

If you want easier solution than implementing whole physics, you can take a look at love.physics module
User avatar
BrotSagtMist
Party member
Posts: 607
Joined: Fri Aug 06, 2021 10:30 pm

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

Post by BrotSagtMist »

Thats already a three lines solution. Hard to make it any easier.
Where is it troubling you?
obey
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

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

Post 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.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 44 guests