Hi ! I just started learning love2d and im making a smash bros like game with bump.lua but it hasn't gravity fonctionality.
Can someone help me how to implement it please ?
Gravity
Re: Gravity
Just add the vertical acceleration multiple dt to you vertical velocity and than vertical velocity multiple dt to your vertical position.chocolat_en_poudre wrote: ↑Mon Oct 23, 2023 1:38 pm Hi ! I just started learning love2d and im making a smash bros like game with bump.lua but it hasn't gravity fonctionality.
Can someone help me how to implement it please ?
Re: Gravity
darkfrei wrote: ↑Mon Oct 23, 2023 3:13 pmJust add the vertical acceleration multiple dt to you vertical velocity and than vertical velocity multiple dt to your vertical position.chocolat_en_poudre wrote: ↑Mon Oct 23, 2023 1:38 pm Hi ! I just started learning love2d and im making a smash bros like game with bump.lua but it hasn't gravity fonctionality.
Can someone help me how to implement it please ?
F = m * a. m = mass. a = -9.8m/s^2 at ~ sea level (gravity). -> a = F/m. Given mass of your player, F is solved for.
velocity is the integral of acceleration. If you are not familiar with calculus, calculate velocity incrementally each timestep (using dt) i.e. v = dt * a, where a (accel due to gravity) is negative (see above, -9.8). the negative denotes down. positive is up. The second integral of accel is position, FYI.
Re: Gravity
Almost righttourgen wrote: ↑Tue Oct 24, 2023 1:03 am F = m * a. m = mass. a = -9.8m/s^2 at ~ sea level (gravity). -> a = F/m. Given mass of your player, F is solved for.
velocity is the integral of acceleration. If you are not familiar with calculus, calculate velocity incrementally each timestep (using dt) i.e. v = dt * a, where a (accel due to gravity) is negative (see above, -9.8). the negative denotes down. positive is up. The second integral of accel is position, FYI.
But the gravity is an acceleration without a = F/m, this acceleration is absolute same for heavy and light masses, you can skip here any mass using. It's enough:
Code: Select all
vy = vy + dt*g -- positive g to fall down (positive Y direction)
y = y + dt*vy
Code: Select all
-- see https://love2d.org/forums/viewtopic.php?p=256873#p256873
y = y + dt*(vy + dt*g/2) -- changing position to half changed velocity
vy = vy + dt*g -- full changed velocity
-
- Prole
- Posts: 2
- Joined: Mon Oct 23, 2023 1:33 pm
Re: Gravity
thanksdarkfrei wrote: ↑Tue Oct 24, 2023 8:39 amAlmost righttourgen wrote: ↑Tue Oct 24, 2023 1:03 am F = m * a. m = mass. a = -9.8m/s^2 at ~ sea level (gravity). -> a = F/m. Given mass of your player, F is solved for.
velocity is the integral of acceleration. If you are not familiar with calculus, calculate velocity incrementally each timestep (using dt) i.e. v = dt * a, where a (accel due to gravity) is negative (see above, -9.8). the negative denotes down. positive is up. The second integral of accel is position, FYI.
But the gravity is an acceleration without a = F/m, this acceleration is absolute same for heavy and light masses, you can skip here any mass using. It's enough:Of if you want to be more precise:Code: Select all
vy = vy + dt*g -- positive g to fall down (positive Y direction) y = y + dt*vy
Code: Select all
-- see https://love2d.org/forums/viewtopic.php?p=256873#p256873 y = y + dt*(vy + dt*g/2) -- changing position to half changed velocity vy = vy + dt*g -- full changed velocity
Re: Gravity
tourgen has a point IF you are going to need more forces to be applied to the object. You first calculate the force due to gravity times mass (i.e. the weight), then add it to all other forces acting on the object, and then obtain the final acceleration of the object by dividing the resulting force by the object's mass.
In many platformers, you can do away without any of these as darkfrei points out.
But watch out: acceleration is a vector. It has a magnitude of 9.8 m/s² and a direction pointing down. Problem is, in Löve, "down" is positive y, therefore the sign of the y coordinate of the acceleration needs to be positive too. Either that, or you build a system with coordinate transforms and everything just to change the vertical sign convention, which sounds a bit overkill.
In many platformers, you can do away without any of these as darkfrei points out.
But watch out: acceleration is a vector. It has a magnitude of 9.8 m/s² and a direction pointing down. Problem is, in Löve, "down" is positive y, therefore the sign of the y coordinate of the acceleration needs to be positive too. Either that, or you build a system with coordinate transforms and everything just to change the vertical sign convention, which sounds a bit overkill.
Re: Gravity
Yeah, i a waiting for the first game, with negative gravity.
Author of the vape knigge. I have thought of you! is much better than "i have waited for you".
Who is online
Users browsing this forum: No registered users and 15 guests