How to make a platformer without knowing much about physics ?

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
Raj
Prole
Posts: 15
Joined: Sun Nov 05, 2017 3:40 pm

How to make a platformer without knowing much about physics ?

Post by Raj »

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?
User avatar
Marty
Citizen
Posts: 89
Joined: Mon Dec 04, 2017 1:47 am
Location: Germany

Re: How to make a platformer without knowing much about physics ?

Post by Marty »

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.
Visual Studio Code TemplateRichLÖVE Mobile (AdMob+UnityAds+PlayGamesServices+GameCenter)Add me on Discord

───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░░░░░░░░█────
▄▄──█░░░▀█▀░░░█──▄▄
█░░█▀▄░░░░░░░▄▀█░░█
User avatar
Raj
Prole
Posts: 15
Joined: Sun Nov 05, 2017 3:40 pm

Re: How to make a platformer without knowing much about physics ?

Post by Raj »

modiX wrote: Mon Dec 11, 2017 11:45 am A simple platformer like Super Mario would never profit from a physics engine considering the trade-offs, imho.
But if I don't use physics then how will I be able to simulate those jumping and running like super mario bros does ?
User avatar
Marty
Citizen
Posts: 89
Joined: Mon Dec 04, 2017 1:47 am
Location: Germany

Re: How to make a platformer without knowing much about physics ?

Post by Marty »

Raj wrote: Mon Dec 11, 2017 11:49 am But if I don't use physics then how will I be able to simulate those jumping and running like super mario bros does ?
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 TemplateRichLÖVE Mobile (AdMob+UnityAds+PlayGamesServices+GameCenter)Add me on Discord

───▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄───
───█▒▒░░░░░░░░░▒▒█───
────█░░░░░░░░░█────
▄▄──█░░░▀█▀░░░█──▄▄
█░░█▀▄░░░░░░░▄▀█░░█
jdoolin
Prole
Posts: 31
Joined: Sat Nov 18, 2017 7:40 pm

Re: How to make a platformer without knowing much about physics ?

Post by jdoolin »

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!
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: How to make a platformer without knowing much about physics ?

Post by ivan »

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.

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)
jdoolin
Prole
Posts: 31
Joined: Sat Nov 18, 2017 7:40 pm

Re: How to make a platformer without knowing much about physics ?

Post by jdoolin »

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
Bookmarked! Thanks. I'll incorporate that gravity calculation.

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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 136 guests