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. Dismiss Notice

HELP XROT

Discussion in 'Scripting' started by AntoineH1, Jan 6, 2021.

  1. AntoineH1

    AntoineH1

    Joined:
    Jan 6, 2021
    Posts:
    3
    Hi ! :) I am really a noob in C + coding, so I would like someone to help me; D on the console there are three errors that I cannot fix, look at the screens and the sripts


    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(PlayerMotor))]
    4. public class PlayerController : MonoBehaviour
    5. {
    6.     [SerializeField]
    7.     private float speed;
    8.  
    9.     [SerializeField]
    10.     private float mouseSensitivity;
    11.  
    12.     private PlayerMotor motor;
    13.  
    14.     private void Start()
    15.     {
    16.         motor = GetComponent<PlayerMotor>();
    17.     }
    18.  
    19.     private void Update()
    20.     {
    21.         // Calculer la vélociter (la vitesse) du mouvement de notre joueur
    22.         float xMov = Input.GetAxisRaw("Horizontal");
    23.         float zMov = Input.GetAxisRaw("Vertical");
    24.  
    25.         Vector3 moveHorizontal = transform.right * xMov;
    26.         Vector3 moveVertical = transform.forward * zMov;
    27.  
    28.         Vector3 velocity = (moveHorizontal + moveVertical).normalized * speed;
    29.  
    30.         motor.Move(velocity);
    31.  
    32.         // Calculer la rotation du joueur en un Vector3
    33.         float yRot = Input.GetAxisRaw("Mouse X");
    34.  
    35.         Vector3 rotation = new Vector3(0, yRot, 0) * mouseSensitivity;
    36.  
    37.         motor.Rotate(rotation);
    38.     }
    39.  
    40.     // Calculer la rotation de la caméra en un Vector3
    41.     {  
    42.          float xRot = Input.GetAxisRaw("Mouse Y");
    43.  
    44.         Vector3 cr = new Vector3(xRot, 0, 0) * mouseSensitivity;
    45.  
    46.         motor.RotateCamera(cr);
    47.     }
    48. }
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(Rigidbody))]
    4. public class PlayerMotor : MonoBehaviour
    5. {
    6.     [SerializeField]
    7.     private Camera cam;
    8.  
    9.     private Vector3 velocity;
    10.     private Vector3 rotation;
    11.     private Vector3 cr;
    12.  
    13.     private Rigidbody rb;
    14.  
    15.     private void Start()
    16.     {
    17.         rb = GetComponent<Rigidbody>();
    18.     }
    19.  
    20.     public void Move(Vector3 _velocity)
    21.     {
    22.         velocity = _velocity;
    23.     }
    24.  
    25.    public void Rotate(Vector3 _rotation)
    26.     {
    27.         rotation = _rotation;
    28.     }
    29.  
    30.     public void RotateCamera(Vector3 _cr)
    31.     {
    32.         cr = _cr;
    33.     }
    34.  
    35.     private void FixedUpdate()
    36.     {
    37.         PerformMouvement();
    38.         PerformRotation();
    39.     }
    40.  
    41.     private void PerformMouvement()
    42.     {
    43.         if(velocity != Vector3.zero)
    44.         {
    45.             rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
    46.         }
    47.     }
    48.  
    49.     private void PerformRotation()
    50.     {
    51.         rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));
    52.         cam.transform.Rotate(-cr);
    53.     }
    54. }
    55.  
     

    Attached Files:

    Last edited: Jan 6, 2021
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,833
    Please use code tags, and paste error messages into your post as text.

    It looks like you are missing a semicolon near the end of your last file.
     
  3. AntoineH1

    AntoineH1

    Joined:
    Jan 6, 2021
    Posts:
    3

    When I get it; its me my another mistake
     
  4. AntoineH1

    AntoineH1

    Joined:
    Jan 6, 2021
    Posts:
    3
    Assets\PlayerController.cs(46,31): error CS1519: Invalid token ';' in class, struct, or interface member declaration
     
  5. Omniglitch

    Omniglitch

    Joined:
    May 29, 2017
    Posts:
    37
    In the PlayerController class, it looks like you forgot to declare the function for block of code between lines 41 and 47. As it is, that code exists outside of any function and the compiler doesn't know what to do with it, producing the strange errors.