Collision Help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 15
- Joined: Sat Jul 07, 2012 2:02 pm
Collision Help
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)
Re: Collision Help
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.
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
-
- Prole
- Posts: 15
- Joined: Sat Jul 07, 2012 2:02 pm
Re: Collision Help
I've encountered an error when adding the collision to my code.
This is lines 52 onward.
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)
- josefnpat
- Inner party member
- Posts: 955
- Joined: Wed Oct 05, 2011 1:36 am
- Location: your basement
- Contact:
Re: Collision Help
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?
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
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
-
- Prole
- Posts: 15
- Joined: Sat Jul 07, 2012 2:02 pm
Re: Collision Help
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)
Re: Collision Help
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.
And when that's done, attention! Your parameters on the Collision check are nil!
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
"Docendo discimus" - Lucius Annaeus Seneca
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot] and 4 guests