#My new code :§

1 messages · Page 1 of 1 (latest)

royal nova
#

I changed the code but create the thread so it won't flood the main chat, here is the code :
Should I do another change before developping walking/running movement, double jump, coyote time and why not wall jump ?

#

    private void Update()
    { 
        // Vérification de la position du joueur, est-il au sol ?
        grounded = IsPlayerGrounded();

        CalculateWASPMovement();
        CalculateJump();
        ApplyMovement();
        ApplyGravity();
    }
    
    private bool IsPlayerGrounded()
    {
        return Physics.Raycast(transform.position, Vector3.down, raycastDetection, 1 << LayerMask.NameToLayer("Ground"));
    }

    private void CalculateWASPMovement()
    {
        // Valeur de l'input dans le Vecteur inputWASPValue.
        Vector2 inputWASPValue = inputManager.GetPlayerWASPMovement();
        // Attribution de ce vecteur 2D à un vecteur 3D.
        waspMovementVector = new Vector3(inputWASPValue.x * playerData.walkingSpeed, 0, inputWASPValue.y * playerData.walkingSpeed);
    }

    private void CalculateJump()
    {
        if (grounded && inputManager.PlayerJumpedThisFrame())
        {
            playerVelocity.y = Mathf.Sqrt(playerData.jumpHeight * -3.0f * gravity);
        } 
    }

    private void ApplyMovement()
    {
        movementVector = new Vector3(waspMovementVector.x, playerVelocity.y, waspMovementVector.z);
        characterController.Move(movementVector * Time.deltaTime);
    }

    void ApplyGravity()
    {
        if (!grounded)
        {
            playerVelocity.y += gravity * playerData.fallingSpeed * Time.deltaTime;
            characterController.Move(playerVelocity*Time.deltaTime);
        } else if (grounded && playerVelocity.y <= 0)
        {
            playerVelocity.y = 0;
        }
    }```