I'm trying to make a simple platformer in love2D. Currently I've got my player class down among other stuff (collision handling class, level classes etc)
The main problem I'm having is jumping. I just can't get it to work properly.
When I jump, the player gets pulled back down too fast to actually make the jump useful. Why is this happening? This is code ported over from ROBLOX, and in ROBLOX Studio, the jumping works normally.
This is inside the player's update function which is called every frame from love.update:
if not love.keyboard.isDown("a") and not love.keyboard.isDown("d") then
self.Velocity=self.Velocity * Vector2.new(0.95,1)
end
if self.Velocity.Y < -self.maxFallVel then
self.Velocity=Vector2.new(self.Velocity.X,self.maxFallVel)
end
if love.keyboard.isDown("d") and self.Velocity.X<self.maxVel and not love.keyboard.isDown("a") then
self.Velocity = self.Velocity+Vector2.new(.1,0) -- right movement
end
if love.keyboard.isDown("a") and self.Velocity.X<self.maxVel and not love.keyboard.isDown("d") then
self.Velocity = self.Velocity-Vector2.new(.1,0) -- left movement
end
if love.keyboard.isDown("space") and self.hasCollision and not self.Jumped then
if self.Velocity.Y == 0 then
self.Velocity.Y = -30
end
end
self.Position=self.Position+Vector2.new(self.Velocity.X,self.Velocity.Y)
if not self.hasCollision then self.Velocity.Y = self.Velocity.Y - self.Gravity end
When I check for collisions inside the main.lua file, that's where I set the variable self.hasCollision to true or false.