Love2d and collisions

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Kevin Tillman
Prole
Posts: 14
Joined: Sun Nov 22, 2009 12:42 am

Love2d and collisions

Post by Kevin Tillman »

Hello, I have been through the documentation on mini physics and I have expiramented with the code. But I have no clue where to begin when dealing with triggering events from collisions. I have set up two hampster balls from the mini physics documentation and I want a sound effect to play when a collision happenes between the two balls, but which functions of love2d do I use? Are they the contact functions for the shapes?
And also, how would I set that up through code? Could someone give me an example to go by please. 8-)
User avatar
steventrouble
Prole
Posts: 5
Joined: Tue Dec 01, 2009 3:00 am

Re: Love2d and collisions

Post by steventrouble »

AHA! There's some pretty good physics and collision checking documentation here:
http://love2d.org/docs/love_physics.html
Kevin Tillman
Prole
Posts: 14
Joined: Sun Nov 22, 2009 12:42 am

Re: Love2d and collisions

Post by Kevin Tillman »

AHA! There's some pretty good physics and collision checking documentation here:
http://love2d.org/docs/love_physics.html
Nothing is explained....granted the explanations on things in the tutorials are descent, but that only goes so far...

http://love2d.org/forum/viewtopic.php?f=3&t=853

my thoughts exactly.....

an engine is only as good as its documentation....
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Love2d and collisions

Post by bartbes »

But you might also know that documentation and open-source projects have a long-term bad relationship..
And I can argue that a coder is as good as his own code...
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Love2d and collisions

Post by Robin »

bartbes wrote:But you might also know that documentation and open-source projects have a long-term bad relationship..
And I can argue that a coder is as good as his own code...
And if a documenter is as good as his own documentation, we can infer we need good documenters. ;)

Volunteers?
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Love2d and collisions

Post by kikito »

I've been thinking about this and I've got several suggestions:

Some random ideas:
  • Making a forum thread for "documentation volunteers". There, people would say "I have created this tutorial / I have finished updating this potato stuff". I could create this thread myself, but I think it would get more attention if someone from the LÖVE core team did it - so it looked more "official".
  • Maybe some sort of contest? eg: the person that documents more or better gets his feature requests on the issue tracker prioritized.
  • Or a small/symbolic incentive system. Eg. those providing nice tutorials will get a "documentator bage" (like a small icon visible under their forum picture). See the badges system on stackoverflow.com. The vBulletin forum engine supports this kind of "awards". I don't know if the one used in LÖVE does. If not, a symbolic "documentator" role (not different from regular users except for the name of the role and maybe the link color) would be just fine, too.
I've also have several wiki-specific suggestions:
  • We need a standarized way to differentiate between 0.5 and 0.6 stuff. For example, if someone adapts the callback tutorial to .6, we need to decide how should be the new tutorial named. Should we rename the 0.5 version, too?
  • Or, we could have a completely separated 0.6 wiki,
  • Or, some kind of "tag", "branch" or "subfolder" for the 0.6 stuff. I don't know if the current LÖVE wiki supports this stuff.
  • Provided that we resolve the 0.5 vs 0.6 stuff, I think we should start linking to wiki articles from the potato doc. Maybe a :wiki tag? Otherwise we can just link using urls.
I can more or less document the Physics part (warning: it will take loooooong) . But I still haven't touched images or sound, and I've just started with the input system, so I hope there are better candidates for this.
When I write def I mean function.
scirath
Citizen
Posts: 85
Joined: Mon Feb 23, 2009 4:44 am

Re: Love2d and collisions

Post by scirath »

Tongue-in-cheek suggestion for the documentation badge name: Uber-Ink God.
(USER MIGHT BE BANNED FOR THIS POST.)
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: Love2d and collisions

Post by pekka »

Please start a new thread about the documentation project. It needs more visibility. I'll answer the original quetsion here to encourage that, and hopefully help the guy who asked.

In Box2D and Löve we use callbacks that are triggered when collisions and related events occur. Here is what Löve docs have to say about setting callbacks:

http://love2d.org/docs/World_setCallbacks_1.html

Note the connection to Shape:setData. You set the data field in each shape to tell them apart and then write the callback to deal with this data appropriately. As it says in the setData docs, you can put table references there, but really anything is OK, as long as you can treat it usefully.

The final callback is briefly explained in Box2D documentation, in case you are curious. It has to do with constraint solving related to situations where (possibly many) objects collide. I have yet to need it for anything I've done with Löve, so you can probably ignore it for a while too.

Note that if you destroy or otherwise mess with you objects in the callback, it may lead to the whole program crashing. A better way is to set some flag the means the object will be destroyed before next update. In the words of the Box2D docs:
It is tempting to implement game logic that alters the physics world inside a contact callback. For example, you may have a collision that applies damage and try to destroy the associated actor and its rigid body. However, Box2D does not allow you to alter the physics world inside a callback because you might destroy objects that Box2D is currently processing, leading to orphaned pointers.

The recommended practice for processing contact points is to buffer all contact points that you care about and process them after the time step. You should always process the contact points immediately after the time step, otherwise some other client code might alter the physics world, invalidating the contact buffer. When you process the contact point buffer you can alter the physics world, but you still need to be careful that you don't orphan pointers stored in the contact point buffer. The testbed has example contact point processing that is safe from orphaned pointers.
(Box2D is of course the C++ library that Löve uses for physics simulation.)
Post Reply

Who is online

Users browsing this forum: No registered users and 227 guests