I am still very new to Unity, so this might be a dumb question, but I have spent some time trying to create a 2D Character controller from the ground up for a school project I’m working on,
and the movement works just fine, but whenever it comes to jumping, my character does a small bounce before jumping,
This is a gif of what happens whenever my character jumps:
(https://i.gyazo.com/735264eaeb46b62ae44937cf5bc07a9a.mp4)
My character movement script is the following:
public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D rigidbody;
public BoxCollider2D collider2D;
[SerializeField] LayerMask groundLayer;
public float JumpStrenght;
public float SideStrenght;
float SideMovement;
float UpwardsMovement;
void Update() {
SideMovement = Input.GetAxis("Horizontal") * SideStrenght;
UpwardsMovement = Input.GetAxis("Vertical") * JumpStrenght;
}
private void FixedUpdate() {
MoveAround(SideMovement);
JumpAround(UpwardsMovement);
}
void MoveAround(float xAxis) {
rigidbody.velocity = new Vector2(xAxis, rigidbody.velocity.y);
}
void JumpAround(float yAxis) {
if (isGrounded() && yAxis != 0) {
Debug.Log("got to jump");
rigidbody.velocity = new Vector2(rigidbody.velocity.x, yAxis + 1);
}
}
bool isGrounded() {
RaycastHit2D hit2D = Physics2D.BoxCast(collider2D.bounds.center, collider2D.bounds.size, 0f, new Vector2(0, -1), 0.10f, groundLayer);
if (hit2D.collider != null) {
return true;
}
else {
return false;
}
}
}
I use a BoxCast to know wheter or not my character is grounded, and that works out alright, but the jump is the only thing that has gotten me scrambling my brains over. I’d really appreciate some help