[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

## How to make a portal in a game Started by Thodan Apr 01 2019 03:58 AM

4 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

### Thodan

[GLOBAL: userInfoPane.html]
Thodan
• Observer

• 11 posts
• Corona SDK

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

[TOPIC: post.html]
#2

### XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
• Contributor

• 884 posts
• Corona SDK

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.

[TOPIC: post.html]
#3

### Thodan

[GLOBAL: userInfoPane.html]
Thodan
• Observer

• 11 posts
• Corona SDK

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

[TOPIC: post.html]
#4

### XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
• Contributor

• 884 posts
• Corona SDK

```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.

[TOPIC: post.html]
#5

### Thodan

[GLOBAL: userInfoPane.html]
Thodan
• Observer

• 11 posts
• Corona SDK

that works fine

thanks a lot

[topic_controls]

[/topic_controls]