- Home /
Teleporting To Back Of Object?
Hello Unity3D.I have a question about teleporting?How can i make it that my character teleporting to an object but it teleports 5 feet behind the object?For example.Whenever i press my teleport key my character teleports to the object but it teleports right on top of the object.What i want is that,whenever i press my teleport key my character teleports 5 feet behind the object so that my character doesn't get clamped up with the object.If anyone knows how i can do this?Can you please tell me how?
P.S Here is the script if anyone needs it.
var amount : float = 5;
var player : Transform;
var enemy : Transform;
function Update () {
var player = GameObject.FindWithTag("Player").transform;
var enemy = GameObject.FindWithTag("Dummy").transform;
if(Input.GetKeyDown("t")) {
animation.Play("Teleport");
Switch();
}
}
function Switch()
{
yield WaitForSeconds(.5);
player.transform.position = enemy.transform.position - enemy.transform.forward * amount;//change position to secondObject, whatever that is.
}
Answer by giulio-pierucci · Feb 10, 2015 at 06:26 PM
player.transform.position = enemy.transform.position - enemy.transform.forward * ammount
ammount is a float (distance)
Oh $$anonymous$$y God,Thank you!!!.I have been stuck on This for 5 days...
Your answer
Follow this Question
Related Questions
Stick an object to the ground while moving? 1 Answer
Physics.Raycast.hit not working properly with moving chars... 1 Answer
Can't detect collision. 1 Answer
Object Collision PLEASE HELP!!! 1 Answer
Movement Direction Problem 1 Answer