Wrapping around the world

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
pib
Prole
Posts: 4
Joined: Thu Jan 14, 2010 1:42 am

Wrapping around the world

Post by pib »

I'm attempting to create a game where objects wrap around at the edges of the world, but I'm running into an issue with the physics engine.

What I'm doing at the moment is simply moving the objects to the other side of the screen when they reach an edge, but when one object pops to the other side of the screen and lands on top of another object, suddenly collisions no longer register for one or both of those objects (at least that seems to be what triggers it).

What would you guys suggest as a solution for this problem and/or as a different way of achieving the effect I'm looking for (wrapping around at the edge of the screen)?

I've attached a .love that demonstrates the problem.
Attachments
toroid.love
(606 Bytes) Downloaded 175 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Wrapping around the world

Post by Robin »

Maybe this works: wrap them as soon as they touch the edge, and put them just outside the edge. Example:

Code: Select all

  |    ()  | ball going right
  |      ()| ball touches edge ..
()|        | .. and is transferred to the left of the edge of the screen
Help us help you: attach a .love.
pib
Prole
Posts: 4
Joined: Thu Jan 14, 2010 1:42 am

Re: Wrapping around the world

Post by pib »

Hmm, I could see how that might work, unless of course one object wraps on top of that same out-of-bounds object.

Plus, the objects will pop from one side to the other pretty badly in this case.

Also, I'd have to keep track on which direction the ball is moving and distinguish between "the ball just went off the left edge going left" and "the ball just went off the right edge, and therefore is now to the left of the left edge.

I'm thinking what I'll have to end up doing is handling collision detection manually, especially since I plan on having the objects visually wrap as well, meaning I'll have up to 4 copies of the same object at a time, in the case where an object is in the corner of the screen, and I'll want to handle collision with that object in any of the four corners.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Wrapping around the world

Post by Robin »

pib wrote:I'm thinking what I'll have to end up doing is handling collision detection manually, especially since I plan on having the objects visually wrap as well, meaning I'll have up to 4 copies of the same object at a time, in the case where an object is in the corner of the screen, and I'll want to handle collision with that object in any of the four corners.
In that case, handling collisions manually will be a lot easier and effective, yes.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest