I wonder how to make a portal in my game. So if I shoot a ball against a rectangle it comes out of another rectangle in another place with the same speed and direction.
can someone help me with this?
Jump to content
It really depends on what kind of portals we are talking about.
At its simplest, you could create rectangular physics sensors for your portals. Then, in your collision listener, you would simply move the x and y coordinates of any object that touches a portal to the portal's counterpart. By adjusting the object's x and y coordinates like that, you wouldn't affect the physics at all.
Now, if you want something fancier, like portals that can be rotated, which affects the direction that the objects move to, then you probably want to get the object's linear x and y velocity. You can calculate the object's velocity vector using them. With that, you'd then adjust the velocity vector with the portal's rotation, etc. etc.
If you want that an object can be split between two locations, i.e. they can be halfway through a portal and appear in two locations, then you'd have to get creative.