#ValdemarF question about portals
1 messages · Page 1 of 1 (latest)
I am not sure what you are asking here.
Can you give us more details?
@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
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
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
If you get in from the front you get out from the front?
Is it an instant tp?
Yes
The code I pasted works for the tp, just not rotation, not sure how to handle it
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
Is there more than a back and front?
And the portal should be a prefab. You are gonna save so much time like that
True
I was asking if you wanted the position to be relative from the place you get in from the place you get out.
No, only rotation
The position is just the position of the other portal
Like that :
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
Not sure what you mean
But the rotation should change, based on side entered, this is important because you can also shoot through them, so it also changes the bullets direction
I think you will be ok
They will only be one-sided then
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
The speed will be the same, but the direction will be the same, if shot through either side, which is what I wanna fix
Are the bullet always going the same speed?
My old project is openning, give me some time
Alright
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?
This will just make the bullet go in the direction of the portals rotation though?
No matter what
bulletRigidBoddy.AddForce(direction.normalized * BulletForce, ForceMode2D.Force);
Ho yeah
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.
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
And the bullet go where they are suppose to ?