The game is a tile based 2d platformer. Separately handling the velocity and acceleration on the player causes it to bug out. This happens cause the player's velocity becomes big enough to phase through the platform. How do I go about checking if the player is grounded or not, since I can change the y velocity of the player to 0. Currently I have to manually set the velocity to 0 after every frame and as a result I cant implement gravity
Asked
Active
Viewed 79 times
0
-
"Separately handling the velocity and acceleration on the player" - please explain what you mean by this. – Dai Mar 05 '21 at 02:53
-
Is this your own engine or are you using an existing engine? How are you modelling movement in your program? Are you familiar with, for example, rectilinear motion, [SUVAT](https://en.wikipedia.org/wiki/Equations_of_motion), kinematics, etc? – Dai Mar 05 '21 at 02:54
-
@Dai I am working on my own 2D tile based engine in Phython using pygame. Yes I am familiar with rectilinear motion, kinematics and anything in physics etc. What do you mean by how I am modeling movement ? I press wasd keys for moving in the appropriate directions. I want to be able to apply forces in the character and hence I need to separately handle velocity and acceleration. – Sivansh Gupta Mar 05 '21 at 05:49
-
@Dai "separately handling velocity and acceleration" by this I mean, I have a physics update function in the payer class where the acceleration is added to the velocity and velocity is added to the position of the player. I can completely ignore Physics and just keep a move vector which gets reset to 0 after every update, but doing this doesnt let me apply any force on the player. – Sivansh Gupta Mar 05 '21 at 05:55
-
@SivanshGupta If you keep adding acceleration to the velocity, the velocity will keep changing and possibly will keep growing in magnitude. That is probably why your player gets ejected from the screen. If you have horizontal ground, you need collision detection in order to know whether the player is on the ground and apply ground's normal reaction to balance out the gravity. If you want accelerations, then when you press a button, acceleration may occur and the velocity will keep increasing until you let go. Then the player will move with that velocity until you deccellerate. – Futurologist Mar 05 '21 at 21:22