Search Unity

Resolved I need help with the movement script.

Discussion in 'Scripting' started by NotNikto, Jan 17, 2021.

  1. NotNikto

    NotNikto

    Joined:
    Jan 17, 2021
    Posts:
    8
    I am on unity version 2019.4.18f1 Personal, and i have a problem with the movement code i have tried to do. Im not sure but it may be because the input system was updated. If anyone wants to help me and try the script, fix the problem and send me the solved code i would appreciate that. Thanks
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Mouselook : MonoBehaviour
    6. {
    7.  
    8.     public float mouseSensitivity - 100f;
    9.  
    10.     public Transform playerbody;
    11.  
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.  
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    22.         float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
    23.  
    24.         playerBody.Rotate(Vector3.up) * mouseX)
    25.     }
    26. }
    27.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    Looks great to me. You gotta debug it and see what is going on in your setup.

    Remember code is only 10% of the problem. The rest is scene setup, connections, the input manager, etc.

    To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run?
    - what are the values of the variables involved? Are they initialized?

    Knowing this information will help you reason about the behavior you are seeing.
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    playerBody.Rotate(Vector3.up) * mouseX)


    Extra ')' in the middle there, and a missing semicolon. Are you seeing compiler errors?
     
  4. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    also
    public float mouseSensitivity - 100f;
    should be
    public float mouseSensitivity = 100f;