Ok so basically when I start up the game everythings normal but if I move or jump or do anything my charater shrinks to like 1 or -1 I forgot which one. Also the ground boxes are a bit weird but I’m pretty sure thats just from my awful design
Heres my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playermovement : MonoBehaviour {
public float movementSpeed;
public Rigidbody2D rb;
public Animator anim;
public float jumpForce = 20f;
public Transform Player;
public LayerMask GroundLayers;
float mx;
private void Update() {
mx = Input.GetAxisRaw("Horizontal");
if (Input.GetButtonDown("Jump") && IsGrounded()) {
Jump();
}
if (Mathf.Abs(mx) > 0.05f) {
anim.SetBool("isrunning", true);
} else {
anim.SetBool("isrunning", false);
}
if (mx > 0f) {
transform.localScale = new Vector3(1f, 1f, 1f);
} else if (mx < 0f) {
transform.localScale = new Vector3(-1f, 1f, 1f);
}
anim.SetBool("IsGrounded", IsGrounded());
}
private void FixedUpdate() {
Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
rb.velocity = movement;
}
void Jump() {
Vector2 movement = new Vector2(rb.velocity.x, jumpForce);
rb.velocity = movement;
}
public bool IsGrounded() {
Collider2D GroundCheck = Physics2D.OverlapCircle(Player.position, 2f, GroundLayers);
if (GroundCheck != null) {
return true;
}
return false;
}
}