Page 2 of 2

Re: My platformer

Posted: Thu Aug 04, 2016 6:29 pm
by 4aiman
1. Create a variable to store the gravity. Let us call that "grav".
2. Assign some value to it. Variable lets you change the strength of the gravity and it's direction. Let it be that grav = 10. Just for example.
3. Create a variable with your current Y-axis speed. Let us call that y_vel.
4. Every love.update increase the speed: y_vel = y_vel+grav.

Now you have everything to go further. The length of a way something passes is speed*time.
You have both:
  • dt in love.update stores the amount of time you haven't take into account yet
  • y_vel stores your Y-axis speed.
5. y=y+y_vel*dt

Now all you have to do is check for collisions and react to the results.
This is a very library-specific process, but generally all you need to do would be:
  • check, whether there is a collision
  • if there is, check whether it should be acknowledged as one that hinders your movement.
Obviously enough, you should check for collisions every frame in love.update to not miss anything.
Basically, whenever your_Y_coordinate+your_Height is bigger or equal to a platform's_Y_coordinate you should stop your movement.
Setting y_vel to 0 is a way to do this: with y_vel==0 the [5] would look like y=y+0*dt. Ergo, you won't move by Y-axis.

But simple check for coordinates may result in passing through thin floors.
I recommend you to try out Bump. It is rather simple to use and have descent documentation.
Here's the library and the documentation: https://github.com/kikito/bump.lua

You also can use my platformer prototype to learn a thing or two on how to utilize a fraction of Bump's power.
I humbly ask to not go further than fair dealing, though. Thanks in advance! :nyu:

Re: My platformer

Posted: Thu Aug 04, 2016 9:08 pm
by CanadianGamer
4aiman wrote:1. Create a variable to store the gravity. Let us call that "grav".
2. Assign some value to it. Variable lets you change the strength of the gravity and it's direction. Let it be that grav = 10. Just for example.
3. Create a variable with your current Y-axis speed. Let us call that y_vel.
4. Every love.update increase the speed: y_vel = y_vel+grav.

Now you have everything to go further. The length of a way something passes is speed*time.
You have both:
  • dt in love.update stores the amount of time you haven't take into account yet
  • y_vel stores your Y-axis speed.
5. y=y+y_vel*dt

Now all you have to do is check for collisions and react to the results.
This is a very library-specific process, but generally all you need to do would be:
  • check, whether there is a collision
  • if there is, check whether it should be acknowledged as one that hinders your movement.
Obviously enough, you should check for collisions every frame in love.update to not miss anything.
Basically, whenever your_Y_coordinate+your_Height is bigger or equal to a platform's_Y_coordinate you should stop your movement.
Setting y_vel to 0 is a way to do this: with y_vel==0 the [5] would look like y=y+0*dt. Ergo, you won't move by Y-axis.

But simple check for coordinates may result in passing through thin floors.
I recommend you to try out Bump. It is rather simple to use and have descent documentation.
Here's the library and the documentation: https://github.com/kikito/bump.lua

You also can use my platformer prototype to learn a thing or two on how to utilize a fraction of Bump's power.
I humbly ask to not go further than fair dealing, though. Thanks in advance! :nyu:

Thanks man I was really confused.

Re: My platformer

Posted: Mon Aug 15, 2016 7:15 am
by steVeRoll
And suddenly this topic turned into a tutorial... huh