Apply Velocity

Hi, all! I’m doing a portal-esque thing here…

I have two portals, when the character goes through a portal, I would like it so that when he pops out at the other one, he is:

  1. A couple hundredths of a unit away from the direction the exit portal is facing, so that he does not just get sucked back in to that one.
  2. and has velocity applied to him in the direction the portal is facing. Like if he walks at the blue portal the speed he is walking plus a little more is applied in the direction of the exit portal when he comes out of it.

Is this achievable?

Thanks!-YA

I would play with triggers
OnEnter -executes if “isWalkingThroughPortal2” is set to false. It sets “isWalkingThroughPortal1” to true, then teleports the player to the other portal and keeps applying the force until he leaves the second portal’s trigger - then “isWalkingThroughPortal1” is set to false

same for other portal but with switched variables.
Hope it sounds any good ^^"

oh yeah I have the switching portal system working fine… I just need help on the above questions…

ah sorry misread a bit ^^" yeah this is achivable. Just force transform.position of the player beyond “sucking” reach then apply force to rigidbody. Should work fine.

yes but I don’t know how I would get the direction the portal is facing. That’s all I really need, now isn’t it? I just need a Vector3 of the portal’s orientation relative to the face that is facing outwards. That’s really what I need…

Anyone know how to do that?

xD

Also, you don’t apply velocity, you set velocity. You apply a force. :slight_smile:

Wait in the first example script, does it take all of the velocity the rigidbody had before and just redirect it on the forward axis? If so that is exactly what I need.

For some odd reason this is not working… My trigger is not activating.

Script on player:

var Red: Transform;
var Blue : Transform;
function Update(){
	if(SwitchPortals.hit == "Blue"){
		transform.position = Red.transform.position;
	}
	if(SwitchPortals.hit == "Red"){
		transform.position = Blue.transform.position;
	}
	
	
		
}

Script on trigger:

var Blue : Transform;
var Red : Transform;
static var hit = "";
function OnTriggerEnter(object : Collider){
	if(object.gameObject.tag == "Blue"){
		hit = "Blue";
		Debug.Log("Blue");
	}
	
	if(object.gameObject.tag == "Red"){
		hit = "Red";
		Debug.Log("Red");

	}
}