#ValdemarF question about portals

1 messages · Page 1 of 1 (latest)

latent ember
#

I am not sure what you are asking here.

#

Can you give us more details?

#

@lilac flame

lilac flame
#

Sure, so I have a portal system that looks like this, where the first number is a "pair index", so 1.1 tp's to 1.2 and so on

#

The teleportation works, but I want it to work so each portal has a front and back basically, where if you enter the front of portal 1.1 you get out of the front of portal 1.2

#

The issue atm is that no matter which side of 1.1 you enter, you get out of the front of 1.2

#

Hope that explains it better

latent ember
#

You want the player to be able to spawn in the same direction as the enter a portal. Is that what you want?

#

If the guy enters from the left, he gets out from the left vice-versa

lilac flame
#

Not really, should've explained that, because portals can be rotated lol

#

The purple things are portals

#

So front would be the rotation of the portal, and back would be the opposite

latent ember
#

If you get in from the front you get out from the front?

lilac flame
#

Exactly

#

of the other portal ofc

latent ember
#

Is it an instant tp?

lilac flame
#

Yes

#

The code I pasted works for the tp, just not rotation, not sure how to handle it

latent ember
#

Why not just place down an empty game object at the front of a portal and tp the player there if he gets in from the front?

#

Same thing for the back

lilac flame
#

Ohhhh yeah, so each portal has two points

#

Would work yeah

#

I'll try

latent ember
#

Is there more than a back and front?

lilac flame
#

No

#

I thought what you meant is one object for the front and one for the back?

latent ember
#

And the portal should be a prefab. You are gonna save so much time like that

lilac flame
#

True

latent ember
lilac flame
#

The position is just the position of the other portal

latent ember
#

If you always get out from the same place, that would be fine.

#

And I don't think the player is going to realize

#

Specially if you don't allow them to see through portals

lilac flame
lilac flame
lilac flame
latent ember
#

Ho wait no. I just realized the speed of the bullet won't be ok

#

That doesn't solve anything 😂

#

I am dumb

#

2 sec I got to test something

lilac flame
#

The speed will be the same, but the direction will be the same, if shot through either side, which is what I wanna fix

latent ember
lilac flame
#

Yes

#

No acceleration

latent ember
#

My old project is openning, give me some time

lilac flame
#

Alright

latent ember
#

I got a solution all written down

#

You will need to reset the velocity of the bullet

#

And multiply it by a Vector3 describing the direction at which the portal is going.

#

@lilac flame did you get what I meant?

lilac flame
#

No matter what

latent ember
#

bulletRigidBoddy.AddForce(direction.normalized * BulletForce, ForceMode2D.Force);

latent ember
#

I think you get get the velocity using rigidbody.velocity, normalize it, then add it to the direction normalized, and then normalize again.

#

You multiplie by the old velocity the number you get from that.

#

I think

#

that might work

#

Did you get what I meant? @lilac flame

#

I am not sure about the math, but I am pretty sure you need to use the normalized velocity of the bullet at some point.

lilac flame
#

Sorry didn't see you sent a message

#

Found a fix, pretty much

#
            Transform otherPortal = FindOtherPortal(firstPortal);
            Transform goTransform = go.transform;

            Vector3 firstPortalForward = firstPortal.forward;

            float relativeRotationY = Quaternion.FromToRotation(goTransform.forward, firstPortalForward).eulerAngles.y;

            Vector3 finalPosition = otherPortal.position;
            Quaternion finalRotation;
            if(relativeRotationY < 90) { // Entered from front
                finalRotation = otherPortal.rotation;
            } else { // Entered from back
                finalRotation = Quaternion.Euler(otherPortal.rotation.eulerAngles - new Vector3(0, 180, 0));
            }

            goTransform.SetPositionAndRotation(finalPosition, finalRotation);
#

Way more complicated than what I anticipated

latent ember