Search Unity

rotate player ?

Discussion in 'Scripting' started by maximmolek785439, Jan 6, 2022.

  1. maximmolek785439

    maximmolek785439

    Joined:
    Sep 19, 2020
    Posts:
    89
    hi do i need help how to rotate the player? thank you in advance for your answer
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class playernew : MonoBehaviour
    6. {
    7.     public float speed;
    8.    
    9.  
    10.     void Update()
    11.     {
    12.         Playermove();
    13.     }
    14.     void Playermove()
    15.     {
    16.         float hor = Input.GetAxis("Horizontal");
    17.         float ver = Input.GetAxis("Vertical");
    18.  
    19.         Vector3 playerMove = new Vector3(hor, 0, ver) * speed * Time.deltaTime;
    20.         transform.Translate(playerMove, Space.Self);
    21.         Vector3 playerRotate = new Vector3(0, 0, ver) * speed * Time.deltaTime;
    22.         transform.Rotate(playerRotate, Space.Self);
    23.     }
    24.  
    25.  
    26. }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
  3. maximmolek785439

    maximmolek785439

    Joined:
    Sep 19, 2020
    Posts:
    89
    it already works just add this:D
    Code (CSharp):
    1.  transform.Rotate(Vector3.up * hor * (100f * Time.deltaTime));