Collision Help

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
Pyromaniac
Prole
Posts: 15
Joined: Sat Jul 07, 2012 2:02 pm

Collision Help

Post by Pyromaniac »

Hi "Lovers", I'm Mainly creating a topic for help with my games collison. I've been having trouble with a few collision detection libs but can't figure out how to use BoundingBox.lua. Can someone give me a rundown on what to do with it?
(Insert funny or inspiring signature here)
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: Collision Help

Post by Petunien »

I've this old collision demo on my disk. It's fully commented out. Hope it helps.

Move the player's rectangle with the arrow keys and collide with the white rectangle.

Please ask if you got questions. :)
Attachments
CollisionExample.love
(1.72 KiB) Downloaded 170 times
"Docendo discimus" - Lucius Annaeus Seneca
Pyromaniac
Prole
Posts: 15
Joined: Sat Jul 07, 2012 2:02 pm

Re: Collision Help

Post by Pyromaniac »

I've encountered an error when adding the collision to my code.

Code: Select all

main.lua:52: attempt to call global 'CheckCollision' (a nil value)


This is lines 52 onward.

Code: Select all

             if CheckCollision(char_x, player_y, 25, 25, ex_x, ex_y, 25, 25) then -- Checks if player and the white rectangle are colliding, if that true -> Print "Ouch!"
		      love.graphics.print("Collided", 10, 10)
              
        
    
end	



function CheckCollision(ax1, ay1, aw, ah, bx1, by1, bw, bh)

  local ax2,ay2,bx2,by2 = ax1 + aw, ay1 + ah, bx1 + bw, by1 + bh
  return ax1 < bx2 and ax2 > bx1 and ay1 < by2 and ay2 > by1
  end
end
(Insert funny or inspiring signature here)
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: Collision Help

Post by josefnpat »

Please supply your .love so we can help you debug.

And next time, please post this in the Support and Development sub-forum.

If possible, could a mod please move this thread?
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
Pyromaniac
Prole
Posts: 15
Joined: Sat Jul 07, 2012 2:02 pm

Re: Collision Help

Post by Pyromaniac »

Sorry for posting this in the wrong section. Attached is the .love file.
Attachments
GravityDeviant.love
Ginger Characters are cool.
(2.14 KiB) Downloaded 147 times
(Insert funny or inspiring signature here)
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: Collision Help

Post by Petunien »

We should have found the error already looking at your posted code.

The "if" that checks for collision doesn't have a "end". The CheckCollision-function does have two instead.

Just put the below one after the if.

Code: Select all

if CheckCollision(char_x, player_y, 25, 25, ex_x, ex_y, 25, 25) then
    love.graphics.print("Collided", 10, 10)  
end   



function CheckCollision(ax1, ay1, aw, ah, bx1, by1, bw, bh)

  local ax2,ay2,bx2,by2 = ax1 + aw, ay1 + ah, bx1 + bw, by1 + bh
  return ax1 < bx2 and ax2 > bx1 and ay1 < by2 and ay2 > by1
end
And when that's done, attention! Your parameters on the Collision check are nil!
"Docendo discimus" - Lucius Annaeus Seneca
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 5 guests