I cut the video off because i started talking about the code for the player but the window didn’t show up on the recording.
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
public Rigidbody2D RB;
public float jumpForce;
private bool isGround;
public Transform groundCheckPoint;
public LayerMask thisIsGround;
private bool doubleJump;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
RB.velocity = new Vector2(moveSpeed * Input.GetAxis("Horizontal"), RB.velocity.y);
isGround = Physics2D.OverlapCircle(groundCheckPoint.position, .2f, thisIsGround);
if (isGround)
{
doubleJump = true;
}
if(Input.GetButtonDown("Jump"))
{
if(isGround)
{
RB.velocity = new Vector2(RB.velocity.x, jumpForce);
}
else
{
if (doubleJump)
{
RB.velocity = new Vector2(RB.velocity.x, jumpForce);
doubleJump = false;
}
}
}
}
}
There’s nothing wrong with BoxCollider2D or anything. What debugging have you done with your OverlapCircle? I mean, your problem centers around your “isGround” flag so that needs checking. I don’t see any gizmos such as the colliders when you’re playing or you drawing a circle (Gizmo.DrawSphere) which you’re checking. Also, make the IsGround/double jump public so you can see them in the inspector.
The position might not be correct or something else. Beyond that you’re saying OverlapCircle isn’t working which just cannot be the case being as nothing has changed there for years and it’s such a simple call.
There’s also a mix of using a composite but the colliders there are not using the component so without seeing gizmos, who knows what’s there.
Whatever is going wrong here, a far better method for detecting things is using contacts and querying them. There’s a whole bunch of API calls for this but here’s an example of some of it used for IsGrounded checking. You can look at my repo to see code and experiment with it.
I’ll add finally that unless you’ve selected physic to run per-frame, it doesn’t. It runs during the fixed update which by default is 50Hz. If your framerate is 250fps then you’ll get 5 frame updates for every single simulation update. Things like Rigidbody2D positions and other stuff doesn’t change until the simulation runs so you setting that velocity won’t have had an effect by the time the next update comes (it might’ve but not guaranteed).
I have no idea of your experience here so I have to throw it all out there.
Never mind I figured out the problem, I made a new character and didn’t move the overlapCircle when I did that so it was constantly always slightly to the left.