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.
Wrapping around the world
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Wrapping around the world
- Attachments
-
- toroid.love
- (606 Bytes) Downloaded 175 times
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Wrapping around the world
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.
Re: Wrapping around the world
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.
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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Wrapping around the world
In that case, handling collisions manually will be a lot easier and effective, yes.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.
Help us help you: attach a .love.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], kov_serg and 10 guests