Hi guys, I need help with my character's movement. As of now, the character is able to move and jump however it can't jump over a platform. I'm not sure if that bug comes from the movement, jumping, or if I should add another method to implement it.
static void movement(void){
position_goal = CP_Vector_Set(0.0f, 0.0f);
float dt = CP_System_GetDt();
player_speed = speed_modifier * dt * 30;
if (CP_Input_KeyDown(KEY_LEFT)) {
position_goal = CP_Vector_Add(position_goal, CP_Vector_Set(-player_speed, .0f));
}
if (CP_Input_KeyDown(KEY_RIGHT)) {
position_goal = CP_Vector_Add(position_goal, CP_Vector_Set(player_speed, .0f));
}
position = CP_Vector_Add(position, position_goal);
}
static void jump(void){
CP_BOOL on_ground = position.y >= ground;
if (CP_Input_KeyTriggered(KEY_UP) && on_ground) {
velocity_goal.y = -jump_power;
}
if (position.y + jump_limit < ground) {
if(velocity_goal.y <= 0)
velocity_goal.y++;
if (velocity_goal.y > 0)
velocity_goal.y = 0;
}
jump_velocity.y = velocity_goal.y * CP_System_GetDt() * 250;
if (!on_ground){
jump_velocity.y += gravity.y * CP_System_GetDt() * 200;
}
position = CP_Vector_Add(position, jump_velocity);
}