Search Unity

Teleport script

Discussion in 'Scripting' started by Quiet_Apples_Studios, May 5, 2020.

  1. Quiet_Apples_Studios

    Quiet_Apples_Studios

    Joined:
    Jan 27, 2020
    Posts:
    17
    Hello I need help with this code, I'm trying to get the player to move a set distance forward when I press Q but right now its pretty inconsistent, when I press Q, it will somtimes go straight forward and other times start making me go right or left randomly.

    Code (CSharp):
    1.     private void Teleport()
    2.     {
    3.         //if the q key is pressed
    4.         //move the transform forward
    5.         if (Input.GetKeyDown(KeyCode.Q))
    6.         {
    7.             transform.position = transform.position + new Vector3(transform.position.x, 2, 0);
    8.             Debug.Log("QQQQQ");
    9.         }
    10.     }
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438