Collisions - love.physics or Hardon Collider?

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
AlexsSteel
Prole
Posts: 17
Joined: Sat Dec 27, 2014 2:11 am

Collisions - love.physics or Hardon Collider?

Post by AlexsSteel »

Hello,

I'm working on a platform game, but i can't decide if should i use the physics module or Hardon Collider to do some movements like these:

Image
(The object rotate when falls from a corner)

Image
(The object go up on the platform, even if it's a rotated rectangle)

Image
(The object is jumping and is able to slide when touch the ceil)

Is the love.physics module necessary or may the Hardon Collider be enough?
Which one is more efficient?
How can I do that movements?
If my project have a tile-based map, which one is the best alternative to deal with it?
What method may be more efficient to detect collisions with every tile?

* I'm sorry about my english.
Relazy
Citizen
Posts: 51
Joined: Thu Jul 10, 2014 11:10 pm

Re: Collisions - love.physics or Hardon Collider?

Post by Relazy »

You may want to look at:
viewtopic.php?f=5&t=76983

It depends on how much physics you want to implement into your game.

Hardon collider implements minimal physics and therefore may not be optimal if you are trying to implement complex physics. In your example from the corner example I can see that the plugin that you require will need physics in some form as the colision rectangle is rotated based upon the surface it has colided with. STI mentioned above has something similar to that.

Although I don't doubt that you can program that in without physics, if you are willing to put the effort in.
User avatar
AlexsSteel
Prole
Posts: 17
Joined: Sat Dec 27, 2014 2:11 am

Re: Collisions - love.physics or Hardon Collider?

Post by AlexsSteel »

Uhm...

If my project have a tile-based map, which one is the best alternative to deal with it?
What method may be more efficient to detect collisions with every tile?
Relazy
Citizen
Posts: 51
Joined: Thu Jul 10, 2014 11:10 pm

Re: Collisions - love.physics or Hardon Collider?

Post by Relazy »

AlexsSteel wrote: If my project have a tile-based map, which one is the best alternative to deal with it?
Did you have a look at STI (the link I posted)? It looks the closest to what you might want although if you dislike it then I'd say go with hardon collider.
AlexsSteel wrote: What method may be more efficient to detect collisions with every tile?
Its a strange question. Why would you want to check collision with every tile? Do you have a player? Or are you working on a particle based game?

If you already have a player then you can just check if the player's collision box collides with anything and then if it's a tile then do something such as set the y velocity or x velocity on the time of collision. For simple collision such as that you can use Hardon Collider.
If you are working on a particle based game then go for love.physics.

But consider that jumping into love.physics may overwhelm you a little bit especially if you just started out with love2d.

However I am not sure if you will be able to use hardon collider for slopes and your corner example..

There is a good read on platformer colisions:
http://higherorderfun.com/blog/2012/05/ ... atformers/

Give me the type that you want from the above link and I will try to estimate what you can use.

You may want to read through the hardon collider reference and have a look at its functions such as

Code: Select all

function HC:setPassive(shape, ...)
"Sets shape to be passive. Passive shapes will be subject to collision detection, but will not actively search for collision candidates"
bizziboi
Citizen
Posts: 57
Joined: Sat Apr 16, 2011 9:24 am

Re: Collisions - love.physics or Hardon Collider?

Post by bizziboi »

Your choice should really be based on whether you want physics behaviour for your character.

If you want to bounce boxes around, have things bounce off the player, throwable stuff - box2d should be your choice.

If you want tight controls - other collision routines will give you more control. You can do an oldschool platformer with box2d but you'll invest a lot of time making box2d not do what it wants to do - classic platformers are pretty much counter-physics.

Both can be made to perform well enough in a tile based world.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Collisions - love.physics or Hardon Collider?

Post by ivan »

I agree with bizziboi, you can use Box2d (aka "love.physics") to get similar results to what you want but it probably won't look exactly as you expect.
(The object rotate when falls from a corner)
Yep, that should work well with Box2d.
It will occur when the center of mass of the box goes past the corner of the platform.
Also, the rate at which it rotates will depend on the velocity of the box.
In an old-school platformer you could just play an animation of the character falling.
(The object go up on the platform, even if it's a rotated rectangle)
That will work too but you may have trouble with the corners of "slopes".
In particular, a box will not just slide up corners of slopes, but will usually roll or get stuck as it hits the corner.
(The object is jumping and is able to slide when touch the ceil)
This one will be tricky for Box2D.
Even if you use a circle or an octagon as in your illustration it won't look right.
Primarily because the object will be redirected sideways as it hits the corner.
Jumping is like launching a projectile - imagine throwing a ball at the edge of the ceiling.
It will also lose vertical velocity as it hits the corner, especially if it has friction.
So yes, it can work but it won't "feel" the same like in classic platformers such as Super Mario Bros.

Generally there is a tradeoff between an accurate physics simulation and tight controls.
User avatar
AlexsSteel
Prole
Posts: 17
Joined: Sat Dec 27, 2014 2:11 am

Re: Collisions - love.physics or Hardon Collider?

Post by AlexsSteel »

Thanks for the replies, i'm going to try using Box2D, but i have just one more question:

It's posible to do something like this using a rectangle (or any other shape) with fixed rotation?

Image
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Collisions - love.physics or Hardon Collider?

Post by ivan »

Yes, Box2D supports bodies with "fixed rotation".
"Fixed rotation" is useful for circle shapes too if you want them to produce friction without rotating.
Also, take a look at "setGravityScale(0)" so that your objects don't slide off slopes.
User avatar
AlexsSteel
Prole
Posts: 17
Joined: Sat Dec 27, 2014 2:11 am

Re: Collisions - love.physics or Hardon Collider?

Post by AlexsSteel »

Thanks for your help, i will try it.
Post Reply

Who is online

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