Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

assets\Scripts\Player controller\PlayerMovement.cs(88,59): error CS1026: ) expected

Discussion in 'Scripting' started by Afterlife301209, Jan 11, 2022 at 5:57 AM.

  1. Afterlife301209

    Afterlife301209

    Joined:
    Nov 19, 2021
    Posts:
    40
    //I am getting this error Assets\Scripts\Player controller\PlayerMovement.cs(88,59): error CS1026: ) expected

    Code (CSharp):
    1. //All the movement controllers and scripts are made by plai (youtube). ALL MOVMENT SCRIPT CREDITS TO HIM
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class PlayerMovement : MonoBehaviour
    7. {
    8.     float playerHeight = 2f;
    9.  
    10.     [SerializeField] Transform orientation;
    11.  
    12.     [Header("Movement")]
    13.     [SerializeField] float moveSpeed = 6f;
    14.     [SerializeField] float airMultiplier = 0.4f;
    15.     float movementMultiplier = 10f;
    16.  
    17.     [Header("Sprinting")]
    18.     [SerializeField] float walkSpeed = 4f;
    19.     [SerializeField] float sprintSpeed = 6f;
    20.     [SerializeField] float acceleration = 10f;
    21.  
    22.     [Header("Keybinds")]
    23.     [SerializeField] KeyCode sprintKey = KeyCode.LeftShift;
    24.  
    25.     [Header("Drag")]
    26.     [SerializeField] float groundDrag = 6f;
    27.     [SerializeField] float airDrag = 2f;
    28.  
    29.     float horizontalMovement;
    30.     float verticalMovement;
    31.  
    32.     [Header("Ground Detection")]
    33.     [SerializeField] Transform groundCheck;
    34.     [SerializeField] LayerMask groundMask;
    35.     [SerializeField] float groundDistance = 0.2f;
    36.         public PlayerMovement(bool isGrounded)
    37.         {
    38.             this.isGrounded = isGrounded;
    39.              
    40.         }
    41.             public bool isGrounded { get; private set; }
    42.  
    43.     Vector3 moveDirection;
    44.     Vector3 slopeMoveDirection;
    45.     //rigidbody
    46.     Rigidbody rb;
    47.    
    48.     //Jumping mech
    49.     public Layermask groundLayers;
    50.     public float jumpForce = 7;
    51.     public SphereCollider col;
    52.  
    53.     RaycastHit slopeHit;
    54.  
    55.     private bool OnSlope()
    56.     {
    57.         if (Physics.Raycast(transform.position, Vector3.down, out slopeHit, playerHeight / 2 + 0.5f))
    58.         {
    59.             if (slopeHit.normal != Vector3.up)
    60.             {
    61.                 return true;
    62.             }
    63.             else
    64.             {
    65.                 return false;
    66.             }
    67.         }
    68.         return false;
    69.     }
    70.  
    71.     private void Start()
    72.     {
    73.         rb = GetComponent<Rigidbody>();
    74.         rb.freezeRotation = true;
    75.         col = GetComponent<SphereCollider>();
    76.     }
    77.  
    78.     private void Update()
    79.     {
    80.         isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
    81.  
    82.         MyInput();
    83.         ControlDrag();
    84.         ControlSpeed();
    85.  
    86.         slopeMoveDirection = Vector3.ProjectOnPlane(moveDirection, slopeHit.normal);
    87.  
    88.         if isGrounded && (Input.GetkeyDown(KeyCode.Space))
    89.         {
    90.             rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
    91.         }
    92.     }
    93.  
    94.     void MyInput()
    95.     {
    96.         horizontalMovement = Input.GetAxisRaw("Horizontal");
    97.         verticalMovement = Input.GetAxisRaw("Vertical");
    98.  
    99.         moveDirection = orientation.forward * verticalMovement + orientation.right * horizontalMovement;
    100.     }
    101.  
    102.     void ControlSpeed()
    103.     {
    104.         if (Input.GetKey(sprintKey) && isGrounded)
    105.         {
    106.             moveSpeed = Mathf.Lerp(moveSpeed, sprintSpeed, acceleration * Time.deltaTime);
    107.         }
    108.         else
    109.         {
    110.             moveSpeed = Mathf.Lerp(moveSpeed, walkSpeed, acceleration * Time.deltaTime);
    111.         }
    112.     }
    113.  
    114.     void ControlDrag()
    115.     {
    116.         if (isGrounded)
    117.         {
    118.             rb.drag = groundDrag;
    119.         }
    120.         else
    121.         {
    122.             rb.drag = airDrag;
    123.         }
    124.     }
    125.  
    126.     private void FixedUpdate()
    127.     {
    128.         MovePlayer();
    129.     }
    130.  
    131.     void MovePlayer()
    132.     {
    133.         if (isGrounded && !OnSlope())
    134.         {
    135.             rb.AddForce(moveDirection.normalized * moveSpeed * movementMultiplier, ForceMode.Acceleration);
    136.         }
    137.         else if (isGrounded && OnSlope())
    138.         {
    139.             rb.AddForce(slopeMoveDirection.normalized * moveSpeed * movementMultiplier, ForceMode.Acceleration);
    140.         }
    141.         else if (!isGrounded)
    142.         {
    143.             rb.AddForce(moveDirection.normalized * moveSpeed * movementMultiplier * airMultiplier, ForceMode.Acceleration);
    144.         }
    145.     }
    146.  
    147.     private bool IsGrounded()
    148.     {
    149.         return Physics.CheckCapsule(col.bounds.center, new Vector3( col.bounds.center.x,
    150.         col.bounds.min.y, col.bounds.center.z ), col.radius * 0.9f, groundLayers);
    151.     }
    152. }
     
  2. kamlesh2052

    kamlesh2052

    Joined:
    Feb 17, 2018
    Posts:
    3
    Here you are missing a start and end bracket for if statement
     
    Afterlife301209 likes this.
  3. chikelubaobioraeze

    chikelubaobioraeze

    Joined:
    Jan 11, 2019
    Posts:
    6
    1. if(isGrounded && (Input.GetkeyDown(KeyCode.Space))
    you missed a bracket in the beginning of the if
     
    Afterlife301209 likes this.
  4. Afterlife301209

    Afterlife301209

    Joined:
    Nov 19, 2021
    Posts:
    40
    ok i did that But then im getting a error like
    Assets\Scripts\Player controller\PlayerMovement.cs(88,25): error CS1525: Invalid expression term '&&'
     
  5. Afterlife301209

    Afterlife301209

    Joined:
    Nov 19, 2021
    Posts:
    40
    O
    OHH THANKS
    IM SORRY IM A LITTLE dumb.
    i make alot of typos cuz im just a 13 y/o :(
     
  6. chikelubaobioraeze

    chikelubaobioraeze

    Joined:
    Jan 11, 2019
    Posts:
    6
    remove the bracket infront of the input.getkeydown
     
  7. chikelubaobioraeze

    chikelubaobioraeze

    Joined:
    Jan 11, 2019
    Posts:
    6
    don't worry you will get it
     
  8. Afterlife301209

    Afterlife301209

    Joined:
    Nov 19, 2021
    Posts:
    40
    thanks alot
     
  9. Afterlife301209

    Afterlife301209

    Joined:
    Nov 19, 2021
    Posts:
    40
    t
    thanks but i fixed the rror THANK YOU ALL!
     
  10. chikelubaobioraeze

    chikelubaobioraeze

    Joined:
    Jan 11, 2019
    Posts:
    6
    that's good to hear
     
  11. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,007
    Those numbers after the file name in the error message are the line number and position where the error happened.
     
  12. Afterlife301209

    Afterlife301209

    Joined:
    Nov 19, 2021
    Posts:
    40
    already solved it mate
     
unityunity