Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

rotate and move

Discussion in 'Scripting' started by alfonsogianmarco, Jun 3, 2020.

  1. alfonsogianmarco

    alfonsogianmarco

    Joined:
    May 21, 2020
    Posts:
    3
    hello, im a unity starter and i have this problem on my character.
    i use this to move him.
    float vertical = Input.GetAxis("Vertical") * speed * Time.deltaTime;
    transform.position = transform.position + transform.forward * vertical;
    float horizontal = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
    transform.position = transform.position + transform.right * horizontal;
    but i want him to look at the direction he is going and i have search for it on youtube and cant find the answer . Can anyone help me please .i also use another code to make the camera follow the player and make him rotate with the camera, but i want him to rotate with wads respect to the camera.
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Please use code tags, and for simplicity always include the full source code.

    In you case, however, simple make the camera a child of the character so it moves and rotates with it.
     
  3. alfonsogianmarco

    alfonsogianmarco

    Joined:
    May 21, 2020
    Posts:
    3
    that was how i had it at first but i was not able to move the camera with the mouse. the camera wasmoving with the wads .