How to make a platformer without knowing much about physics ?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How to make a platformer without knowing much about physics ?
I don't have much knowledge of physics. But I really want to make a platformer. Will I ever be able to make a game that is not a puzzle or hangman type game?
Re: How to make a platformer without knowing much about physics ?
I recently came across an interesting article regarding using physics in a platformer: http://www.learn-cocos2d.com/2013/08/ph ... ible-idea/
It explains in detail why physics on a platformer is not a good idea. While it can take much work from you, it can bring a lot of problems with it. It's very interesting.
I think the Box2D physics engine is great to work with in Love2D, but I would limit it to very simple games that require physics. A simple platformer like Super Mario would never profit from a physics engine considering the trade-offs, imho.
But at the end, playing with physics is fun and awesome. A good start is the physics tutorial of Love2D: https://love2d.org/wiki/Tutorial:Physics
Start by trying something simple, like a dynamic ball that you can control on a static platform. Play with restitution, friction, mass etc.
It explains in detail why physics on a platformer is not a good idea. While it can take much work from you, it can bring a lot of problems with it. It's very interesting.
I think the Box2D physics engine is great to work with in Love2D, but I would limit it to very simple games that require physics. A simple platformer like Super Mario would never profit from a physics engine considering the trade-offs, imho.
But at the end, playing with physics is fun and awesome. A good start is the physics tutorial of Love2D: https://love2d.org/wiki/Tutorial:Physics
Start by trying something simple, like a dynamic ball that you can control on a static platform. Play with restitution, friction, mass etc.
Visual Studio Code Template • RichLÖVE Mobile (AdMob+UnityAds+PlayGamesServices+GameCenter) • Add me on Discord
───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░█░░░░░█░░█────
─▄▄──█░░░▀█▀░░░█──▄▄─
█░░█─▀▄░░░░░░░▄▀─█░░█
───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░█░░░░░█░░█────
─▄▄──█░░░▀█▀░░░█──▄▄─
█░░█─▀▄░░░░░░░▄▀─█░░█
Re: How to make a platformer without knowing much about physics ?
Instead of applying force to a body and let the sprite render at the position of the body, you simply move the sprite by setting velocity. You can even build in some acceleration movement.
However, I haven't build a platformer at all so far, so maybe anybody else can give you some more insights.
I suggest you to check the examples that are posted on the forum, there are some that aren't using physics at all.
Visual Studio Code Template • RichLÖVE Mobile (AdMob+UnityAds+PlayGamesServices+GameCenter) • Add me on Discord
───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░█░░░░░█░░█────
─▄▄──█░░░▀█▀░░░█──▄▄─
█░░█─▀▄░░░░░░░▄▀─█░░█
───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░█░░░░░█░░█────
─▄▄──█░░░▀█▀░░░█──▄▄─
█░░█─▀▄░░░░░░░▄▀─█░░█
Re: How to make a platformer without knowing much about physics ?
modiX has the right idea. I've been working on a platformer and spending a good bit of time just on the jump. Here's how I have it working.
My world has a gravity of say, 500. It's basically a measure of the strength of the force pulling my character down (adding to its Y position). This will apply to all characters or entities that are affected by gravity. My character also has what I call a "jump_height", though it's really more of a starting Y velocity. It could be -200. It is negative because to jump "up", the Y position must be decreased.
When the jump begins, the Y position will be changed by ( y_velocity * dt ) each frame. But then the y_velocity is changed by (gravity * dt). So the character will gradually slow down during the jump, meaning the Y position is decreased in smaller increments each frame, until it is finally 0 (the peak of the jump) and then a positive number, meaning the character is now descending.
I'm currently using bump.lua for collision detection and it's a pretty easy check to see if my character has landed (i.e., collided with a platform object).
From there it's all about figuring out your game mechanics and tweaking the values until things feel the way you want them to. You may have to adjust gravity and acceleration values. Do you want to allow a higher jump for holding the button down longer? How much control do you want to allow during the jump? Do you want acceleration or inertia? Acceleration works a lot like the Y position. If you press "right", increase your X velocity by a certain amount each frame until you reach your top speed.
Let me know if any of that makes sense. Good luck and have fun!
My world has a gravity of say, 500. It's basically a measure of the strength of the force pulling my character down (adding to its Y position). This will apply to all characters or entities that are affected by gravity. My character also has what I call a "jump_height", though it's really more of a starting Y velocity. It could be -200. It is negative because to jump "up", the Y position must be decreased.
When the jump begins, the Y position will be changed by ( y_velocity * dt ) each frame. But then the y_velocity is changed by (gravity * dt). So the character will gradually slow down during the jump, meaning the Y position is decreased in smaller increments each frame, until it is finally 0 (the peak of the jump) and then a positive number, meaning the character is now descending.
I'm currently using bump.lua for collision detection and it's a pretty easy check to see if my character has landed (i.e., collided with a platform object).
From there it's all about figuring out your game mechanics and tweaking the values until things feel the way you want them to. You may have to adjust gravity and acceleration values. Do you want to allow a higher jump for holding the button down longer? How much control do you want to allow during the jump? Do you want acceleration or inertia? Acceleration works a lot like the Y position. If you press "right", increase your X velocity by a certain amount each frame until you reach your top speed.
Let me know if any of that makes sense. Good luck and have fun!
Re: How to make a platformer without knowing much about physics ?
I've written a tutorial precisely on this topic:
http://2dengine.com/doc/gs_platformers.html
In short, you need a basic understanding of the underlying physics, fortunately it's not very hard.
Yes, modiX is correct, the simplest solution is to use "impulses" or instant changes in velocity.
There are techniques of calculating constants like gravity - thus you can avoid magic values.
http://2dengine.com/doc/gs_platformers.html
In short, you need a basic understanding of the underlying physics, fortunately it's not very hard.
Yes, modiX is correct, the simplest solution is to use "impulses" or instant changes in velocity.
There are techniques of calculating constants like gravity - thus you can avoid magic values.
Code: Select all
-- what is the gravity that would allow jumping to a given height?
g = (2*jumpHeight)/(timeToApex^2)
-- what is the initial jump velocity?
initJumpVelocity = math.sqrt(2*g*jumpHeight)
Re: How to make a platformer without knowing much about physics ?
Bookmarked! Thanks. I'll incorporate that gravity calculation.ivan wrote: ↑Wed Dec 13, 2017 9:52 am I've written a tutorial precisely on this topic:
http://2dengine.com/doc/gs_platformers.html
I spent a few hours one evening playing various platformers, taking notes on different jump behaviors, including the arcs, minimum heights, falling behaviors, how much control during the jump, etc.
Who is online
Users browsing this forum: Bing [Bot], ChocolateLoxtl and 5 guests