My platformer

Show off your games, demos and other (playable) creations.
User avatar
4aiman
Party member
Posts: 262
Joined: Sat Jan 16, 2016 10:30 am

Re: My platformer

Post 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:
User avatar
CanadianGamer
Party member
Posts: 132
Joined: Tue Jun 30, 2015 1:23 pm
Location: Canada
Contact:

Re: My platformer

Post 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.
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
User avatar
steVeRoll
Party member
Posts: 140
Joined: Sun Feb 14, 2016 1:13 pm

Re: My platformer

Post by steVeRoll »

And suddenly this topic turned into a tutorial... huh
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests