412lop 2023-02-05 03:53
How do you fix these 3 bugs in this code:
1. Character keeps going up and down very rapidly
2. If you hold A your character keeps going up
3. Left and bottom sides of walls you can noclip through
GAMELEGEND 2023-02-05 06:45 (Edited)
Well, I can't really help with the first bug because that has to do with gravity, and I have never been too good at that, but the character keeps going up and up when you hold A because you put BUTTON(0,0) not BUTTON TAP(0,0) so if the user holds the A button the code in the IF statement won't keep running.
The third bug is happening because to get collision you should check every corner of the sprite now to some people it's confusing at first but once that person gets it then it seems so simple. The program below allows the character to freely move around the screen so you can check out the collision and because I'm not good with the gravity stuff I probably can't help with the collision for the jumping.
was8bit 2023-02-05 15:25
You really need to check all four corners, am only checking top left and bottom right, but this gets you started...
was8bit 2023-02-05 15:27
For great precision moving a Sprite against background obsticles check this out...
was8bit 2023-02-05 15:33 (Edited)
Gravity requires an acceleration variable....
Acceleration = Acceleration + GRAVITY CONSTANT
Player Y = Player Y + Acceleration
I limit Acceleration at 1 to create a smooth fall ...
You immediately reset Acceleration to zero if your player is on top of a floor...
You forbid jumping unless your player is on top of a floor
A jump is a one time change of acceleration to a negavite number...
was8bit 2023-02-05 15:36
You can tweak the numbers to create the results you like ;)