Player jumping with bump.lua

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
drikdrok
Prole
Posts: 36
Joined: Sun Mar 15, 2015 9:53 am
Contact:

Player jumping with bump.lua

Post by drikdrok »

So i am working on a small project with a basic player jumping around on a map.
I am following "RazorGameDev"'s tutorial on youtube. But instead of using all the code he made, i tried implementing other libraries i know better. I now use Bump.lua for collision, and the hump camera as the camera. Works fine. Except that my player can jump repeatedly up against a wall. Here's my code:

Code: Select all

	self.x, self.y, collisions = world:move(self, self.x + self.xvel, self.y + self.yvel)
	if keyDown("space") and self.canJump then 
  		self.canJump = false
  		self.yvel = -15.5
	elseif #collisions >= 1 and self.yvel > 0 then 
		self.canJump = true 
	end	

I am aware that the reason he jumps is that nothing in the code prevents him from jumping. But how would I? My best bet would be to find out which side of the player was colliding. This way i see could if the player is on the ground, or has the side to a wall. It would look somthing like:

Code: Select all

	if self.bottom.isColliding then 
  		self.yvel = -15.5
	end

But i have no idea how to achieve this...
Attachments
game.love
(385.69 KiB) Downloaded 87 times
User avatar
tuupakku
Prole
Posts: 21
Joined: Fri Feb 12, 2016 12:12 pm

Re: Player jumping with bump.lua

Post by tuupakku »

I have no experience with bump.lua, but by printing the character yvel to the console I noticed that it's never 0, even when the character is perfectly still. It would probably be easier if your character had an yvel of 0 when still so you could use yvel == 0 as a condition to allow jumping... unless that's not how bump.lua works.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Player jumping with bump.lua

Post by s-ol »

If the collision normal is {0,-1} the collision was at the bottom (nx=0, ny==-1).

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
drikdrok
Prole
Posts: 36
Joined: Sun Mar 15, 2015 9:53 am
Contact:

Re: Player jumping with bump.lua

Post by drikdrok »

S0lll0s wrote:If the collision normal is {0,-1} the collision was at the bottom (nx=0, ny==-1).
Thank you very much! Now I got it to Work just fine :)!
Post Reply

Who is online

Users browsing this forum: No registered users and 234 guests