Sign in to follow this  
Storyyeller

Portals

Recommended Posts

I am currently trying to create a 2d game similar to Portal, but I am stuck on how to represent the state of a wall, in terms of the holes from portals. I need to be able to divide up the interval and create a hole when a portal is created, and then remove that hole when the portal is destroyed. I also need to be able to find which section of the intact wall if any, the bullet collided with and determine if there is enough room in that section to create a new portal. The best I've been able to think of so far is a list of doubles representing the endpoints of each interval, but every single approach I've been able to come up with is messy and error prone. What can I do?

Share this post


Link to post
Share on other sites
What are you using for your levels? Tilemaps? Randomly placed rectangles? Polygons? Either way, the wall hit-detection will most likely boil down to a ray-trace against the surrounding geometry. What exactly have you tried and where did you get stuck?

As for how to logically represent portals, I'd treat them as separate entities, not a state that walls can be in.

Share this post


Link to post
Share on other sites
I'm using Box2d for the collision detection.

And the portals are separate entities, but I still have to keep track of the holes in the walls somehow, so that I can change the wall's shape. Otherwise, things going through the portals will just collide with the wall.

Share this post


Link to post
Share on other sites
Quote:
Original post by Storyyeller
And the portals are separate entities, but I still have to keep track of the holes in the walls somehow, so that I can change the wall's shape. Otherwise, things going through the portals will just collide with the wall.


You should change that. You shouldn't need to change your walls at all. Handle portal collision before you handle wall collision and it should "just work". So basically if you collide with a portal, do the portal teleport logic and early out so that the wall collision tests don't happen.

- me

Share this post


Link to post
Share on other sites
Quote:
Original post by Storyyeller
But Box2d is handling the collision detection. There's no way to change it, short of completely rewriting the library.


Ah. Well since it's a physics engine couldn't you just flip the collision flags for that wall segment to transparent and then add your portal as a physics object to the world?


Google'd up some other suggestions here:
http://www.box2d.org/forum/viewtopic.php?f=3&t=4423

Ha! that's your post [smile]

It's also possible that Box2D might not be the correct physics library for this game, or it might require re-writing parts of the library. You might consider evaluating other physics libraries to see if they provide portal support. Not all tools are created equal.

-me

Share this post


Link to post
Share on other sites
Quote:
Original post by Palidine
Ah. Well since it's a physics engine couldn't you just flip the collision flags for that wall segment to transparent and then add your portal as a physics object to the world?


That just leads right back to my original problem.

Share this post


Link to post
Share on other sites
My project, pseudoform, implements portals by some tricky hooks that disable collisions behind a portal for any contact points of an object going through that portal. Note that contact points in front of the portal are not disabled:


wall
allow | ignore
collisions | collisions
/ `
+----------------|-----+
| |por| |
| |tal| | box
| | | |
+----------------|-----+
` /
|
|


To implement this, your physics engine must provide you with a mechanism to listen for per-contact collisions with the ability to reject them.

Share this post


Link to post
Share on other sites
Quote:
Original post by Storyyeller
That just leads right back to my original problem.


Well. it's 99% a Box2d issue. The way I suggested you doing things in my original post is a "correct" and "simple" way. You say it doesn't work with box2d (which i don't know anything about).

I would look for ways that you can add objects to the Box2d world that have portal functionality. Doing anything with your representation of walls seems like a bad path. What you want to do is drop some object into the simulation that prevents collision detection with the part of the wall that it wraps or is laced in front of. So basically your avatar hits the portal and you get a message back and then you do your teleport logic and you are able to control by return value whether or not you want additional downstream collision effects to take place. It might be possible to "hit" the portal and just flip the collision flags on the avatar so it no longer collides with walls, then teleport and then flip the flags back. This requires that your physics engine supports those kinds of features.

But long story short: you need to learn more about how Box2d works and the full set of features that it supports. If Box2d doesn't have a way to build portals, then choose a different physics library or re-write the relevant code so that it does.

-me

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this