Collision Detection, gravity, and platforms? Oh my!

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.
User avatar
Raylin
Prole
Posts: 30
Joined: Thu Dec 30, 2010 8:48 am
Location: Chicago
Contact:

Collision Detection, gravity, and platforms? Oh my!

Post by Raylin »

Well then.

I'm sure there are about fifty thousand of these topics but none of them seem to directly answer my questions.
So, here's hoping. The questions I have are:

[*] How would one go about making collision detection for a platform? Currently, I'd like a freeform detection and not a map-based one. Now while I am sure that my game will turn into this, I'd like to know the other methods as well.

[*] Then, how would one make gravity realistic enough to be called a platformer? I'm afraid this is the one thing that has evaded my logical mind.

[*] How would a player know which side of a platform it hit? You can understand. I need to kill the X velocity on the sides, reverse the Y velocity on the bottom and halt the Y velocity on the top? (re: platforms and such)

Thank you.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Collision Detection, gravity, and platforms? Oh my!

Post by Robin »

Raylin wrote:How would one go about making collision detection for a platform? Currently, I'd like a freeform detection and not a map-based one. Now while I am sure that my game will turn into this, I'd like to know the other methods as well.
You could use love.physics, but the downside of using that is that it's rather complicated and won't give you "realistic" physics (not realistic for platformers, anyway).

So, writing your own collision detection might be the best option. You can look on the forums around here for inspiration.
Raylin wrote:Then, how would one make gravity realistic enough to be called a platformer? I'm afraid this is the one thing that has evaded my logical mind.
I'm not sure what you mean, but usually, platformers aren't at all realistic in terms of gravity and related subjects, because that would kill the playing experience. But you can usually find the right properties by tweaking the parameters.
Raylin wrote:How would a player know which side of a platform it hit? You can understand. I need to kill the X velocity on the sides, reverse the Y velocity on the bottom and halt the Y velocity on the top? (re: platforms and such)
Compare the x/y of the player and the platform in question.

Also, depending on your previous experience with Lua and LÖVE, you might want to fool around a bit first, to get the feeling for it.
Help us help you: attach a .love.
User avatar
Raylin
Prole
Posts: 30
Joined: Thu Dec 30, 2010 8:48 am
Location: Chicago
Contact:

Re: Collision Detection, gravity, and platforms? Oh my!

Post by Raylin »

Seems simple enough. I'll probably botch up the gravity though. :shock:
I'll work on it some more and then post some code.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Collision Detection, gravity, and platforms? Oh my!

Post by tentus »

If you want, Kurosuke ( http://love2d.org/forums/viewtopic.php?f=5&t=2197 ) is open source, I've tried to make it kinda flexible and easy to read. If nothing else, it can give you some ideas for how to pull stuff off.
Kurosuke needs beta testers
User avatar
Raylin
Prole
Posts: 30
Joined: Thu Dec 30, 2010 8:48 am
Location: Chicago
Contact:

Re: Collision Detection, gravity, and platforms? Oh my!

Post by Raylin »

Thank you for that, sir. Very helpful.

Now, I am fiddling around with the ParticleSystem.
Are there any tutorials on that in the forum?

EDIT: Sorry about that. I didn't know that having the start() method in love.update didn't conflict. (Meaning I thought it would only emit one particle)
EDIT 2: FFFFFF- I can't have just rectangular collisions. I need a way for asymmetrical collision detection...
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Collision Detection, gravity, and platforms? Oh my!

Post by tentus »

To the best of my knowledge, Love supports polygonal shapes of up to 8 sides (physics shapes are used for collision in Kurosuke). In the ramp object I use a three sided polygon to create a triangle. In the player avatar I use a circle.

I'm fairly sure you can lock multiple shapes to a single body: I've thought about putting a head shape on the player several times, but the benefits weren't worth the extra work.
Kurosuke needs beta testers
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Collision Detection, gravity, and platforms? Oh my!

Post by Robin »

The problem with Kurosuke is that it uses love.physics, which famously is not recommended for platformers.
Help us help you: attach a .love.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Collision Detection, gravity, and platforms? Oh my!

Post by Taehl »

Raylin wrote:[*] How would one go about making collision detection for a platform? Currently, I'd like a freeform detection and not a map-based one. Now while I am sure that my game will turn into this, I'd like to know the other methods as well.

[*] Then, how would one make gravity realistic enough to be called a platformer? I'm afraid this is the one thing that has evaded my logical mind.

[*] How would a player know which side of a platform it hit? You can understand. I need to kill the X velocity on the sides, reverse the Y velocity on the bottom and halt the Y velocity on the top? (re: platforms and such)
1) At its simplest: Check the player's coordinates against those of your platform. If they intersect, don't let the player move there.

2) Make the downward force increase over time. What I like doing is giving the player object momentum which changes their position, rather than changing position directly (for example, in love.update, do player.x, player.y = player.x+player.momentum.x, player.y+player.momentum.y. Also, make sure to decrease momentum every frame, with something like player.momentum.x, player.momentum.y = player.momentum.x*.9, player.momentum.y*.9). By making the controls affect momentum rather than position, you can also get "running start" and "skidding to a halt" stuff. When falling, just increment their downwards momentum every frame (say, player.momentum.y = player.momentum.y - dt). This will give you very natural logarithmic falls, ballistic curves, and so on.

3) As Robin said.

Despite what everyone will tell you, you CAN use the physics engine for a platformer if you're careful. But the only real reason to do this is if you want the player to be able to interact with physics objects in your game.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Collision Detection, gravity, and platforms? Oh my!

Post by tentus »

Despite what everyone will tell you, you CAN use the physics engine for a platformer if you're careful. But the only real reason to do this is if you want the player to be able to interact with physics objects in your game.
And if you want collisions to be with anything other than rectangles. I would dearly like to see someone write collision in Love that is not physics based AND can do non-rectangles, but I suspect that the comparative ease of using physics like I have will prevent that from ever happening.

Also, playing with boxes is fun. :3
Kurosuke needs beta testers
User avatar
Raylin
Prole
Posts: 30
Joined: Thu Dec 30, 2010 8:48 am
Location: Chicago
Contact:

Re: Collision Detection, gravity, and platforms? Oh my!

Post by Raylin »

What I'm thinking about doing will involve a table that takes the bounding box of ALL the collidables and comparing the player bounding box with it...

But, how fast would that be?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 73 guests