Teleporting projectiles, and maintaining speed

Hi, I’m trying to teleport a projectile from one teleport to another, by shooting into the first one. I also want the projectiles speed to be maintained when exiting the second teleporter.

This is my code:

#pragma strict
var teleportTo : Transform;

function OnTriggerEnter (col : Collider)

{
col.transform.position = teleportTo.position;
}

The projectile does indeed get teleported as wanted, but it does not keep its speed and will immediately drop to the ground. Any help would be appreciated :slight_smile:

Create a variable that stores the value of the current speed of the projectile before the teleport, then you use this value in the AddForce rigidbody when it is teleported;)

I hope I have helped :wink:

Vote +1 :stuck_out_tongue:

ok if it has a rigidbody then make a function Update and put the line of script below in it.

transform.rigidbody.AddForce(transform.forward * speed);

Just make a speed variable after that and it should work.

Just as Unamine suggested. Something like;

var teleportTo : Transform;

function OnTriggerEnter (col : Collider)
{ 
	var vel : Vector3 = col.rigidbody.velocity;
	col.transform.position = teleportTo.position;
	col.rigidbody.Addforce(vel, ForceMode.Acceleration);
}