Brackeys / 2D-Character-Controller

Free 2D Character Controller for Unity.
https://youtu.be/dwcT-Dch0bA
1.16k stars 1.62k forks source link

Jump and Crouch Not Working #48

Open AnshrajGamez opened 2 years ago

AnshrajGamez commented 2 years ago

My code:

`using UnityEngine;

public class PlayerMovement : MonoBehaviour { CharacterController2D controller2D; float horizontalMove = 0f; float runSpeed = 70f; bool jump = false; bool crouch = false; // Update is called once per frame void Update() { horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed; if (Input.GetButtonDown("Jump")) { jump = true; }

    if (Input.GetButtonDown("Crouch"))
    {
        crouch = true;
    }
    else if (Input.GetButtonUp("Crouch"))
    {
        crouch = false;
    }
}

void FixedUpdate()
{
    controller2D = GameObject.Find("Player").GetComponent<CharacterController2D>();
    controller2D.move(horizontalMove * Time.fixedDeltaTime, crouch, jump, controller2D.GetOnCrouchEvent());

}

} `

MinerMinerMods commented 1 year ago

Hi there, do you have 2 hitboxes? If you don't then change your player's hitbox in to a top and bottom hitbox then input the top hitbox into hitbox disable. for anything else check the video here