Unity Error CS0201, (45,13), i want to reduce the air strafing on my game, i did this by dividing the speed of the character by a number of my choice

Viewed 11

unity gives an error that states: Only assignmetns, call, increment, decrement, await, and new object expressions can be used as a statement. if there is any way to reduce airstrafing that you may know of it would be very useful is you could share it with me. Unity Error CS0201, (45,13) it basically reffers to the if command cointainign the this piece of code: speed/airResistance .

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ThirdPersonMovement : MonoBehaviour
{
   // this controll the camera movement 
    public CharacterController controller;
    public Transform cam;
    public float turnSmoothTime = 0.1f;
    float turnSmoothVelocity;

   // gravity speed and jump
    public float speed = 6f; 
    public float gravity = -9.81f;
    public float jumpHeight = 3f;
    public float airResistance = 2f;

    // this is the ground check
    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;

    // this is still gravity i think :)
    Vector3 velocity;
    bool isGrounded;
       
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }
    
    void Update()
    {

        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if(isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }

        if (isGrounded = false)
        {
            speed/airResistance;
        }
        
        
        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical = Input.GetAxisRaw("Vertical");
       
        Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;

        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);

       // jumping 
        if(Input.GetButtonDown("Jump") && isGrounded)
       {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
       }
      
       // camera movement damping and such
        if (direction.magnitude >= 0.1f)
        {
            float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
            float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
            transform.rotation = Quaternion.Euler(0f, angle, 0f);

            Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;

            controller.Move(moveDir.normalized * speed * Time.deltaTime);

        }
       
    }
}
0 Answers
Related