Hello,
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?
Thanks!
Thodan
Hello,
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?
Thanks!
Thodan
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.
thanks for the reply!
It doesnt have to be a complicated, so the first option would be good.
in the collision listener how do I move the x and y coordinates? not with a transition.to right?
Thanks
object.x = portal2.x object.y = portal2.y
You don’t necessarily need to do anything fancier. This won’t affect the physics and just snaps the object to the 2nd portal.
You’ll need to just know what portal was collided with and where the object needs to be sent to.
that works fine
thanks a lot
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.
thanks for the reply!
It doesnt have to be a complicated, so the first option would be good.
in the collision listener how do I move the x and y coordinates? not with a transition.to right?
Thanks
object.x = portal2.x object.y = portal2.y
You don’t necessarily need to do anything fancier. This won’t affect the physics and just snaps the object to the 2nd portal.
You’ll need to just know what portal was collided with and where the object needs to be sent to.
that works fine
thanks a lot