void ReadStates()
        {
            CustomInput customInput = CustomInput.Instance;

            this.ReadCameraInput();

            m_ped.MouseScrollInput = Input.mouseScrollDelta;


            m_ped.IsAimOn  = customInput.GetButton("RightClick");
            m_ped.IsFireOn = customInput.GetButton("LeftClick");

            m_ped.IsJumpOn = customInput.GetButton("Jump");


            Vector3 inputMove = Vector3.zero;

            if (m_smoothMovement)
            {
                inputMove = new Vector3(customInput.GetAxis("Horizontal"), 0f, customInput.GetAxis("Vertical"));
            }
            else
            {
                inputMove = new Vector3(customInput.GetAxisRaw("Horizontal"), 0f, customInput.GetAxisRaw("Vertical"));
            }

            if (inputMove.sqrMagnitude > 0f)
            {
                inputMove.Normalize();

                if (customInput.GetButton("Walk"))
                {
                    m_ped.IsWalkOn = true;
                }
                else if (customInput.GetButton("Sprint"))
                {
                    m_ped.IsSprintOn = true;
                }
                else
                {
                    m_ped.IsRunOn = true;
                }
            }

            if (m_ped.Camera != null)
            {
                m_ped.Movement = m_ped.Camera.transform.TransformVector(inputMove).normalized;
            }
            else
            {
                m_ped.Movement = inputMove.normalized;
            }

            if (m_ped.Movement.sqrMagnitude > float.Epsilon)
            {
                // only assign heading if there is any movement - we don't want the heading to be zero vector
                m_ped.Heading = m_ped.Movement;
            }
        }
Exemplo n.º 2
0
        private void Update()
        {
            if (GameManager.IsPaused)
            {
                return;
            }

            if (axes == RotationAxes.MouseXAndY)
            {
                float rotationX = transform.localEulerAngles.y + CustomInput.GetAxis(_MouseX) * sensitivityX;

                rotationY += CustomInput.GetAxis(_MouseY) * sensitivityY;
                rotationY  = Mathf.Clamp(rotationY, minimumY, maximumY);

                transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
            }
            else if (axes == RotationAxes.MouseX)
            {
                transform.Rotate(0, CustomInput.GetAxis(_MouseX) * sensitivityX, 0);
            }
            else
            {
                rotationY += CustomInput.GetAxis(_MouseY) * sensitivityY;
                rotationY  = Mathf.Clamp(rotationY, minimumY, maximumY);

                transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
            }
        }
    private void GetInput(out float speed)
    {
        // Read input
        float horizontal = CustomInput.GetAxis("Horizontal");
        float vertical   = CustomInput.GetAxis("Vertical");

        bool waswalking = m_IsWalking;

#if !MOBILE_INPUT
        // On standalone builds, walk/run speed is modified by a key press.
        // keep track of whether or not the character is walking or running
        m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
#endif
        // set the desired speed to be walking or running
        speed   = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
        m_Input = new Vector2(horizontal, vertical);

        // normalize input if it exceeds 1 in combined length:
        if (m_Input.sqrMagnitude > 1)
        {
            m_Input.Normalize();
        }

        // handle speed change to give an fov kick
        // only if the player is going to a run, is running and the fovkick is to be used
        if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
        {
            StopAllCoroutines();
            StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    private void Update()
    {
        if (currentDevice == LocomotionDeviceManager.Devices.Wasd)
        {
            float horizontal = CustomInput.GetAxis("Horizontal");
            transform.localEulerAngles = transform.localEulerAngles + new Vector3(0.0f, horizontal * turnSpeed * Time.deltaTime, 0.0f);
        }

        // the jump state needs to read here to make sure it is not missed
        if (!m_Jump)
        {
            m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
        }

        if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
        {
            StartCoroutine(m_JumpBob.DoBobCycle());
            PlayLandingSound();
            m_MoveDir.y = 0f;
            m_Jumping   = false;
        }
        if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
        {
            m_MoveDir.y = 0f;
        }

        m_PreviouslyGrounded = m_CharacterController.isGrounded;
    }
        private void Update()
        {
            // Get the input vector from keyboard or analog stick
            var directionVector = new Vector3(CustomInput.GetAxis(_HorizontalAxis), 0, CustomInput.GetAxis(_VerticalAxis));

            // Debug.Log(directionVector);
            if (directionVector != Vector3.zero)
            {
                // Get the length of the directon vector and then normalize it
                // Dividing by the length is cheaper than normalizing when we already have the length anyway
                var directionLength = directionVector.magnitude;
                directionVector = directionVector / directionLength;

                // Make sure the length is no bigger than 1
                directionLength = Mathf.Min(1, directionLength);

                // Make the input vector more sensitive towards the extremes and less sensitive in the middle
                // This makes it easier to control slow speeds when using analog sticks
                directionLength = directionLength * directionLength;

                // Multiply the normalized direction vector by the modified length
                directionVector = directionVector * directionLength;
            }

            // Apply the direction to the CharacterMotor
            motor.inputMoveDirection = transform.rotation * directionVector;


            motor.inputJump = CustomInput.GetButtonDown(_JumpButton);
        }
Exemplo n.º 6
0
    protected virtual void FixedUpdate()
    {
        if (isDead)
        {
            return;
        }

        #region Cette région s'occupe de la gestion des animations
        if (jump.GetComponent <Jump>().getCanJump())
        {
            animator.SetBool(animIsGrounded, true);
        }
        else
        {
            animator.SetBool(animIsGrounded, false);
        }
        // Si le controller est un monstre, on fait le shake de caméra quand il retombe
        if (jump.GetComponent <Jump>().Landed&& GetType() == typeof(MonsterController) && doubleJumped)
        {
            audioSource.PlayOneShot(sounds[1]);
            Camera.main.transform.parent.GetComponent <CameraController>().PlayShakeAnim();
            doubleJumped = false;
        }

        animator.SetFloat(animHorizontalVel, CustomInput.GetAxis(keyBinds[("Horizontal")]));
        animator.SetFloat(animVerticalVel, Mathf.Abs(this.GetComponent <Rigidbody2D>().velocity.y));
        #endregion

        if (jump.GetComponent <Jump>().getCanJump() && CustomInput.GetAxis(keyBinds["Jump"]) != 0 && !timerJump)
        {
            StartCoroutine("timer_jump");
            this.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            this.GetComponent <Rigidbody2D>().AddForce(new Vector2(0, jump_strenght));
        }
        if (jump.GetComponent <Jump> ().getCanJump())
        {
            this.GetComponent <Rigidbody2D>().velocity = new Vector2(0, this.GetComponent <Rigidbody2D>().velocity.y);
        }
        if (CustomInput.GetAxis(keyBinds["Horizontal"]) != 0 && !jump.GetComponent <Jump> ().getCanJump() && !WallJump)
        {
            this.transform.Translate(new Vector2(horizontal_strenght * Time.deltaTime * CustomInput.GetAxis(keyBinds["Horizontal"]) * 0.8f, 0));
        }
        if (CustomInput.GetAxis(keyBinds["Horizontal"]) != 0 && jump.GetComponent <Jump> ().getCanJump())
        {
            this.transform.Translate(new Vector2(horizontal_strenght * Time.deltaTime * CustomInput.GetAxis(keyBinds["Horizontal"]), 0));
        }
        if (CustomInput.GetAxis(keyBinds["Horizontal"]) < 0)
        {
            this.transform.localScale = new Vector2(scale, this.transform.localScale.y);
        }
        else if (CustomInput.GetAxis(keyBinds["Horizontal"]) > 0)
        {
            this.transform.localScale = new Vector2(scale * -1, this.transform.localScale.y);
        }

        if (CustomInput.GetAxis(keyBinds["Fire1"]) == 1 && attackCurrentDelay <= 0)
        {
            Attack();
        }
    }
Exemplo n.º 7
0
    // Update is called once per frame
    void FixedUpdate()
    {
        AIWaypointBehaviour next     = courseController.AIWaypoints[currentWaypointIndex].GetComponent <AIWaypointBehaviour>();
        Vector3             toNextWP = courseController.AIWaypoints[currentWaypointIndex].transform.position - gameObject.transform.position;

        toNextWP.y = 0;

        // steering calculations
        float angleraw = Vector3.SignedAngle(gameObject.transform.forward, toNextWP, Vector3.up);
        float angle    = angleraw * (toNextWP.magnitude < next.DampingDistance ? toNextWP.magnitude / next.DampingDistance : 1);
        float steerpos = CustomInput.GetAxis("Steering");

        // neutral zone didn't work, reset steering when changing direction
        if (steerpos < 0 && angle > 0 || steerpos > 0 && angle < 0)
        {
            steerpos = 0;
        }

        if (angle > 5)
        {
            //Debug.Log("A:" + angle + ";SP:" + (steerpos < 1f ? steerpos + Mathf.Clamp(rb.velocity.magnitude * 0.001f, 0, 0.01f) : steerpos));
            CustomInput.SetAxis("Steering", steerpos < 1f ? steerpos + Mathf.Clamp(rb.velocity.magnitude * 0.001f, 0, 0.01f) : steerpos);
        }
        else if (angle < -5)
        {
            //Debug.Log("A:" + angle + ";SP:" + (steerpos > -1f ? steerpos - Mathf.Clamp(rb.velocity.magnitude * 0.001f, 0, 0.01f) : steerpos));
            CustomInput.SetAxis("Steering", steerpos > -1f ? steerpos - Mathf.Clamp(rb.velocity.magnitude * 0.001f, 0, 0.01f) : steerpos);
        }
        else
        {
            CustomInput.SetAxis("Steering", 0f);
        }

        // throttle and brake calculations
        if (next.WaypointType == AIWaypointType.NORMAL)
        {
            CustomInput.SetAxis("Throttle", 0.5f - Mathf.Abs(CustomInput.GetAxis("Steering")) * Mathf.Clamp(10f - rb.velocity.magnitude, 0, 10f));
            CustomInput.SetAxis("Brake", 0f);
        }
        else if (next.WaypointType == AIWaypointType.BRAKE)
        {
            CustomInput.SetAxis("Throttle", 0f);
            float brake = CustomInput.GetAxis("Brake");
            CustomInput.SetAxis("Brake", brake < 1f ? brake + 0.01f:brake);
        }

        if (toNextWP.magnitude < 10f)
        {
            if (currentWaypointIndex < courseController.AIWaypoints.Length - 1)
            {
                currentWaypointIndex++;
            }
            else
            {
                currentWaypointIndex = 0;
            }
        }
    }
Exemplo n.º 8
0
    public void Update()
    {
        float rotation = customInput.GetAxis("Horizontal");

        if (rotation != 0)
        {
            plane.Rotate(rotation);
        }
        customInput.HandleInput();
    }
Exemplo n.º 9
0
    private void HandleMovement()
    {
        float hax = CustomInput.GetAxis("Horizontal");
        float vax = CustomInput.GetAxis("Vertical");

        if (!(GameScript.instance.controllerState == GameScript.ControllerState.Player && GameScript.instance.isAlive))
        {
            hax = 0;
            vax = 0;
        }

        float horSpeedMultiplier = isWings1Active ? horizontalSpeedSecondMultiplier : horizontalSpeedMultiplier;

        rigidbody2D.velocity = new Vector2(hax * horSpeedMultiplier, vax * verticalSpeedMultiplier);
    }
Exemplo n.º 10
0
 void Turbo()
 {
     if (CustomInput.GetAxis("Throttle") > 0 && engineRPM > engineIdle + 50)
     {
         turboSpool += turboWaste.Evaluate(engineRPM) / (turboSize * 3);
         if (turboSpool > turboWaste.Evaluate(engineRPM))
         {
             turboSpool = turboWaste.Evaluate(engineRPM);
             spooled    = true;
         }
     }
     else
     {
         if (turboSpool > 0.2f)
         {
             spooled     = false;
             turboSpool -= turboSpool / (turboSize * 4);
         }
     }
 }
Exemplo n.º 11
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Rigidbody2D rb = GetComponent <Rigidbody2D>();

        if (Input.GetButton("Accelerate"))
        {
            GetComponent <Rigidbody2D>().AddForce(transform.right * speedForce);
        }

        if (Input.GetButton("Horizontal"))
        {
            CustomInput.SetAxis("Horizontal", Input.GetAxis("Horizontal"));
        }
        else
        {
            CustomInput.SetAxis("Horizontal", 0.0f);
        }

        rb.angularVelocity = (CustomInput.GetAxis("Horizontal") * torqueForce);

        rb.velocity = ForwardVelocity() + LeftVelocity() * driftFactor;
    }
Exemplo n.º 12
0
    void LightsOn()
    {
        if (gear == 595)
        {
            if (Input.GetButtonDown("Lights") && !frontLights.activeSelf)
            {
                frontLights.SetActive(true);
            }
            else if (Input.GetButtonDown("Lights") && frontLights.activeSelf)
            {
                frontLights.SetActive(false);
            }

            if (CustomInput.GetAxis("Brake") > 0f)
            {//brakes
                rearLights.SetActive(true);
            }
            else
            {
                rearLights.SetActive(false);
            }
        }
    }
 private void Update()
 {
     joyAxisWriter.Write(CustomInput.GetAxis(AxisName));
 }
Exemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        if (photonView.isMine)
        {
            if (Input.GetButtonDown("Run"))
            {
                if (!freeRunning)
                {
                    freeRunning = true;
                }
                animator.SetBool("Walking", true);
            }
            if (Input.GetButtonUp("Run"))
            {
                if (freeRunning)
                {
                    freeRunning = false;
                }
                animator.SetBool("Walking", false);
            }
            float strafeInput  = 0;
            float forwardInput = 0;
            if (Input.touchCount == 0)
            {
                strafeInput  = Input.GetAxis("Horizontal");
                forwardInput = Input.GetAxis("Vertical");
            }
            else
            {
                strafeInput  = CustomInput.GetAxis("Horizontal");
                forwardInput = CustomInput.GetAxis("Vertical");
                if (Input.touchCount == 2)
                {
                    freeRunning = true;
                }
                else if (freeRunning)
                {
                    freeRunning = false;
                }
            }
            if (strafeInput != 0 || forwardInput != 0)
            {
                Vector3 dirToMove = Vector3.Normalize(camera.transform.forward * forwardInput
                                                      + camera.transform.right * strafeInput);

                if (!freeRunning)                 //Fighting
                {
                    transform.LookAt(new Vector3(GameObject.Find("Target").gameObject.transform.position.x,
                                                 transform.position.y,
                                                 GameObject.Find("Target").gameObject.transform.position.z));

                    float forwardWeight = Mathf.Sign(Vector3.Dot(dirToMove, transform.forward))
                                          * Vector3.Project(dirToMove, transform.forward.normalized).magnitude;
//					Debug.Log("FORWARD WEIGHT: " + forwardWeight);
                    float strafeWeight = Mathf.Sign(Vector3.Dot(dirToMove, transform.right))
                                         * Vector3.Project(dirToMove, transform.right.normalized).magnitude;
//					Debug.Log("STRAFE WEIGHT: " + strafeWeight);

                    rigidbody.MovePosition(transform.position
                                           + transform.forward * forwardWeight * forwardSpeed
                                           + transform.right * strafeWeight * strafeSpeed);
                }
                else                  //Running
                {
                    Vector3 target = transform.position + dirToMove * 10;
                    transform.LookAt(new Vector3(target.x,
                                                 transform.position.y,
                                                 target.z));
                    rigidbody.MovePosition(transform.position + transform.forward * runSpeed);
                }
            }
        }
    }
Exemplo n.º 15
0
    void FixedUpdate()
    {
        AeroDrag();

        //TireWearMonitor();//remove this sometime just reminder
        if (manual == 2)
        {
            clutchPressure = 1 - CustomInput.GetAxis("Clutch");
        }
        Engine();
        float targetSteering = maxSteerAngle * CustomInput.GetAxis("Steering");

        WheelHit wheelHitR2, wheelHitL2;

        wheelFR.GetGroundHit(out wheelHitR2);
        wheelFL.GetGroundHit(out wheelHitL2);

        HUD.UpdateHUD(engineRPM, engineREDLINE, currentSpeed, shifting, gear, tirewearlist, new float[] { wheelHitL2.forwardSlip * 100, wheelHitR2.forwardSlip * 100, wheelHitL2.sidewaysSlip * 100, wheelHitR2.sidewaysSlip * 100 });

        // FFB calculations
        if (ffbeffect != null)
        {
            WheelHit wheelHitR, wheelHitL, wheelHitRR, wheelHitRL;
            wheelFR.GetGroundHit(out wheelHitR);
            wheelFL.GetGroundHit(out wheelHitL);
            wheelRR.GetGroundHit(out wheelHitRR);
            wheelRL.GetGroundHit(out wheelHitRL);

            if (Input.GetButton("logiquake"))
            {
                // meme
                ffbForce.Magnitude = ffbForce.Magnitude < 0 ? 150000 : -150000;
            }
            else
            {
                // non meme
                // wheel weight calc

                /*float wheelWeight = 1 - ((((wheelHitR.forwardSlip + wheelHitL.forwardSlip) / 2) + ((wheelHitR.sidewaysSlip + wheelHitL.sidewaysSlip) / 2))/2);
                 * float centering = Vector3.SignedAngle(wheelHitR.forwardDir.normalized, GetComponent<Rigidbody>().transform.forward, Vector3.up);
                 * float baseForce = (wheelHitR.force + wheelHitL.force) * 5;
                 * ffbForce.Magnitude = (int) (baseForce * wheelWeight * centering * -0.5);*/
                int centering = Mathf.RoundToInt((Vector3.SignedAngle(wheelHitR.forwardDir.normalized, GetComponent <Rigidbody>().transform.forward, Vector3.up) / maxSteerAngle) * -10000);;
                centeringDebug = centering;

                float computedFFBFront = FFBApproximation(wheelFL, wheelHitL, wheelFR, wheelHitR) / FFBMultiplier;
                float computedFFBRear  = FFBApproximation(wheelRL, wheelHitRL, wheelRR, wheelHitRR) / FFBMultiplier;
                computedFFBDebug     = computedFFBFront;
                computedFFBDebugRear = computedFFBRear;

                ffbForce.Magnitude = Mathf.RoundToInt(centering * (computedFFBFront));
                ffbMagnitude       = ffbForce.Magnitude;
            }
            EffectParameters ffbParams = new EffectParameters();
            ffbParams.Parameters = ffbForce;
            ffbeffect.SetParameters(ffbParams, EffectParameterFlags.TypeSpecificParameters);
        }

        //steering
        wheelFR.steerAngle = targetSteering;
        wheelFL.steerAngle = targetSteering;

        if (aspirated)
        {
            Turbo();
        }

        //currentSpeed = 2 * 22/7 * wheelFL.radius * wheelFL.rpm * 60 / 1000; legacy
        currentSpeed  = 2 * 22 / 7 * wheelFL.radius * ((wheelFL.rpm + wheelFR.rpm) / 2 * FrontWheelDriveBias) * 60 / 1000;
        currentSpeed += 2 * 22 / 7 * wheelRL.radius * ((wheelRL.rpm + wheelRR.rpm) / 2 * (1 - FrontWheelDriveBias)) * 60 / 1000;
        currentSpeed  = Mathf.Round(currentSpeed);
    }
Exemplo n.º 16
0
    void Update()
    {
        float[] shariq = new float[] { wheelFL.rpm, wheelFR.rpm, wheelRL.rpm, wheelRR.rpm };
        //HUD.UpdateHUD(engineRPM, engineREDLINE, currentSpeed, shifting, gear, tirewearlist, shariq);

        Gearbox();    //gearbox update
        //EngineAudio.ProcessSounds(engineRPM, spooled, turboSpool);
        LightsOn();
        if (differentialTrans != null)
        {
            DiffPosition(wheelRRTrans, wheelRLTrans);
        }
        if (drivingWheel != null)
        {
            drivingWheel.transform.localEulerAngles = new Vector3(drivingWheel.transform.rotation.x, drivingWheel.transform.rotation.y, -90 * CustomInput.GetAxis("Steering"));
        }
        if (Input.GetButtonDown("Reset"))
        {
            Debug.Log("Reset was pressed");
            transform.rotation = Quaternion.identity;
            transform.position = new Vector3(transform.position.x, transform.position.y + 5, transform.position.z);
        }
        if (dirt)
        {
            dirt.SetFloat("_FortniteRange", dirtiness);
        }
    }
Exemplo n.º 17
0
    void Engine()
    {     //engine
        if (gear == 1 || clutchPressure < 0.5f)
        { //NEUTRAL
            if (engineRPM >= engineREDLINE)
            {
                engineRPM -= 300;
            }
            else
            {
                engineRPM += engineTorque.Evaluate(engineRPM) * turboSpool * Mathf.Clamp01(CustomInput.GetAxis("Throttle"));
                if (engineRPM > engineIdle && Mathf.Clamp01(CustomInput.GetAxis("Throttle")) == 0)
                {
                    engineRPM -= engineTorque.Evaluate(engineRPM) / 3;
                }
                if (engineRPM < engineIdle)
                {
                    engineRPM += 20;
                }
            }
            clutchRPM           = engineRPM;
            wheelFL.motorTorque = 0;
            wheelFR.motorTorque = 0;
            wheelRL.motorTorque = 0;
            wheelRR.motorTorque = 0;
        }
        else
        {//DRIVE
            engineRPM  = (Mathf.Abs(wheelFL.rpm + wheelFR.rpm) / 2 * FrontWheelDriveBias) * ratio * Mathf.Abs(gears[gear]);
            engineRPM += (Mathf.Abs(wheelRL.rpm + wheelRR.rpm) / 2 * (1 - FrontWheelDriveBias)) * ratio * Mathf.Abs(gears[gear]);
            //make motor torks calc shorter with temporary variable
            float precalc = Mathf.Clamp01(CustomInput.GetAxis("Throttle")) * ((-0.5f + Mathf.Clamp01(gears[gear])) * 2) * clutchPressure * turboSpool;

            wheelFL.motorTorque = (engineTorque.Evaluate(engineRPM) - Differential(wheelFR, wheelFL)) * CenterDifferential(1) * FrontWheelDriveBias * precalc;
            wheelFR.motorTorque = (engineTorque.Evaluate(engineRPM) - Differential(wheelFL, wheelFR)) * CenterDifferential(1) * FrontWheelDriveBias * precalc;
            wheelRL.motorTorque = (engineTorque.Evaluate(engineRPM) - Differential(wheelRR, wheelRL)) * CenterDifferential(-1) * (1 - FrontWheelDriveBias) * precalc;
            wheelRR.motorTorque = (engineTorque.Evaluate(engineRPM) - Differential(wheelRL, wheelRR)) * CenterDifferential(-1) * (1 - FrontWheelDriveBias) * precalc;

            if (engineRPM >= engineREDLINE)
            {//rev limiter
                wheelFL.motorTorque = 0;
                wheelFR.motorTorque = 0;
                wheelRL.motorTorque = 0;
                wheelRR.motorTorque = 0;
            }
            if (engineRPM < engineIdle)
            {//idling
                wheelFL.motorTorque = 100 * FrontWheelDriveBias * ((-0.5f + Mathf.Clamp01(gears[gear])) * 2) * clutchPressure;
                wheelFR.motorTorque = 100 * FrontWheelDriveBias * ((-0.5f + Mathf.Clamp01(gears[gear])) * 2) * clutchPressure;
                wheelRL.motorTorque = 100 * (1 - FrontWheelDriveBias) * ((-0.5f + Mathf.Clamp01(gears[gear])) * 2) * clutchPressure;
                wheelRR.motorTorque = 100 * (1 - FrontWheelDriveBias) * ((-0.5f + Mathf.Clamp01(gears[gear])) * 2) * clutchPressure;
            }
            if (clutchRPM > engineRPM)
            {//clutch kick
                clutchRPM          -= engineTorque.Evaluate(engineRPM);
                engineRPM           = clutchRPM;
                wheelFL.motorTorque = 300 * FrontWheelDriveBias * ((-0.5f + Mathf.Clamp01(gears[gear])) * 2) * clutchPressure;
                wheelFR.motorTorque = 300 * FrontWheelDriveBias * ((-0.5f + Mathf.Clamp01(gears[gear])) * 2) * clutchPressure;
                wheelRL.motorTorque = 300 * (1 - FrontWheelDriveBias) * ((-0.5f + Mathf.Clamp01(gears[gear])) * 2) * clutchPressure;
                wheelRR.motorTorque = 300 * (1 - FrontWheelDriveBias) * ((-0.5f + Mathf.Clamp01(gears[gear])) * 2) * clutchPressure;
            }
            else if (clutchRPM + 300 < engineRPM)
            {
                clutchRPM = 0;
            }
        }

        debug1 = wheelFL.motorTorque;
        debug2 = wheelFR.motorTorque;
        debug3 = wheelRL.motorTorque;
        debug4 = wheelRR.motorTorque;

        wheelRPM = (wheelFL.rpm * 3.3f) * ratio; //speed counter
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        if (time < 0.0f)
        {
            time += Time.deltaTime;
        }

        else if (playerControl)
        {
            time += Time.deltaTime;
            Rigidbody2D rb = GetComponent <Rigidbody2D>();
            if (Input.GetButton("Accelerate"))
            {
                rb.AddForce(transform.right * speedForce);
            }

            if (Input.GetKey("left") || Input.GetKey("right"))
            {
                CustomInput.SetAxis("Horizontal", Input.GetAxis("Horizontal"));
            }
            else
            {
                CustomInput.SetAxis("Horizontal", 0);
            }


            rb.angularVelocity = (CustomInput.GetAxis("Horizontal") * torqueForce);

            rb.velocity = ForwardVelocity() + LeftVelocity() * driftFactor;

            if (hitWall && Parameters.wallDeath)
            {
                Destroy(me);
            }
        }
        else
        {
            // Update fitness
            time        += Time.deltaTime;
            fitness     += Vector3.Distance(lastposition, transform.position);
            lastposition = transform.position;
            // Check if collided with wall and if so update the fitness and destroy yourself
            if (hitWall || time > 70.0f || Parameters.killCommand)
            {
                isDone = true;
            }

            // Raycast
            double[] inputs = Raycast();


            // Now do movement based on that
            double[] outputs = individual.computeOutput(inputs);

            Rigidbody2D rb = GetComponent <Rigidbody2D>();
            if (outputs[0] > 0.5)
            {
                GetComponent <Rigidbody2D>().AddForce(transform.right * speedForce);
            }

            CustomInput.SetAxis("Horizontal", (float)outputs[1]);


            rb.angularVelocity = (CustomInput.GetAxis("Horizontal") * torqueForce);

            rb.velocity = ForwardVelocity() + LeftVelocity() * driftFactor;
        }

        if (Parameters.race && finished)
        {
            if (playerControl)
            {
                text.text = "Finished with time of " + time;
            }
            // Save highscore
            finished = false;
            if (name == null)
            {
                Parameters.listForHighScore.Add(new HighScoreData("Player", finalTime, Parameters.track));
            }
            else
            {
                Parameters.listForHighScore.Add(new HighScoreData(name, finalTime, Parameters.track));
            }
        }

        finalTime = time;
    }