- Home /
"Teleport" in the way the player is heading
I have this script which has a GUI button inside, when i click this button, i want it to make my first person character "teleport" forward in the way it is heading so i have made this script.
function Update () {
if (teleportActive == true) {
transform.position.x += 2.0;
}
}
There is just the problem that, when i use the button it only "teleports" in the x direction (i know that is because it is set to do that), and then when it is "teleporting" it goes to the coordinates 2.0 which it isnt supposed to. I just want it to "teleport" a bit ahead where it is heading. How would i edit the script to make i do that?
Answer by Griffo · Apr 07, 2014 at 08:46 PM
Try
transform.position += transform.forward * 2
Answer by electfall70 · Apr 07, 2014 at 09:17 PM
var PlayerTransform : Transform;
function Update () {
if (teleportActive == true) {
PlayerTransform.transform.position.x += transform.forward * 2.0;
}
}
Your answer
Follow this Question
Related Questions
Character teleports to the apex of full jump height 0 Answers
Moving Forward 1 Answer
Impact Sound When Jumping? (JavaScript) 1 Answer
Jump Script ow to make it??? 2 Answers
3rd person controller, jump Error 1 Answer