I am trying to make a simple side-scroller game in p5.js. As far as I understood I need to have vectors to imitate real-world physics. All I really need is a force that pushed the player down and a force that makes it jump when a key is pressed. I watched a video from youtube on the topic and I am pretty sure I followed it exactly as it was described but I get a different result. My keys don't always get detected and also they are all with different amount of force. Thank you in advance.
// This is a part of a player class that I have
update(){
this.pos.add(this.vel)
this.vel.add(this.acc)
}
applyForce(force){
this.vel.add(force)
}
earth(){
if (this.pos.y > height - 100){
this.pos.y = height - 100
this.acc.y *= 0
}
}
// This is where I detect the pressed key
function keyPressed(){
let jump = createVector(0,-10)
player.applyForce(jump)
}
// And then in the draw function i have this
player.applyForce(gravity)
player.earth()