Page 1 of 1
Changing to Collision?
Posted: Wed Jan 25, 2012 6:11 pm
by AwkwardOrpheus
This is my first time using love2D and Lua and I've kinda went through a workaround for the collision with ground, and I've got no idea how to add collision now.
I honestly don't understand the ground and collision things because my friend helped me do all that but he doesn't how to make a fully working collision onto my ground either.
This was just a little test for me to use with Lua, and I've been adding since.
Anybody up for helping me out?
Re: Changing to Collision?
Posted: Wed Jan 25, 2012 6:27 pm
by baconhawka7x
I don't understand what you are asking, it looks like your collision works just fine.
Re: Changing to Collision?
Posted: Wed Jan 25, 2012 6:30 pm
by AwkwardOrpheus
I mean if I were to add walls, or anything else, all i've added is a floor, and my player isn't colliding to it.
Re: Changing to Collision?
Posted: Wed Jan 25, 2012 6:37 pm
by baconhawka7x
I suggest checking out bounding box collision(
https://love2d.org/wiki/BoundingBox.lua) if you haven't already. But basically you want to get the x and y of the player(Which I'm pretty sure you have already), which are in the top left corner of the picture. Then get all three other corners, do the same for a wall, and then do something like
Code: Select all
if heroCornerLeft.x < wallCornerRight.x then
herocornerLeft.x = wallCornerRight.x
end
But also include the y positions too. The only downside to bounding box is the "box" part:p
Re: Changing to Collision?
Posted: Wed Jan 25, 2012 7:38 pm
by AwkwardOrpheus
baconhawka7x wrote:I suggest checking out bounding box collision(
https://love2d.org/wiki/BoundingBox.lua) if you haven't already. But basically you want to get the x and y of the player(Which I'm pretty sure you have already), which are in the top left corner of the picture. Then get all three other corners, do the same for a wall, and then do something like
Code: Select all
if heroCornerLeft.x < wallCornerRight.x then
herocornerLeft.x = wallCornerRight.x
end
But also include the y positions too. The only downside to bounding box is the "box" part:p
Where would this go?
in:
Code: Select all
function CheckCollision(ax1,ay1,aw,ah, bx1,by1,bw,bh)
?
Re: Changing to Collision?
Posted: Wed Jan 25, 2012 8:19 pm
by Kadoba
He was giving an example on how you resolve the collision. You have to think of collision in two parts: detection and resolution. In other words, first you find out if you have a collision and then you do something about it. In your case you want to move the player out of the floor/wall/whatever.
That CheckCollision function is only the detection part.
Re: Changing to Collision?
Posted: Wed Jan 25, 2012 9:10 pm
by baconhawka7x
Kadoba wrote:He was giving an example on how you resolve the collision. You have to think of collision in two parts: detection and resolution. In other words, first you find out if you have a collision and then you do something about it. In your case you want to move the player out of the floor/wall/whatever.
That CheckCollision function is only the detection part.
Exactly, just do something like
or some such.
Re: Changing to Collision?
Posted: Wed Jan 25, 2012 9:11 pm
by baconhawka7x
Kadoba wrote:He was giving an example on how you resolve the collision. You have to think of collision in two parts: detection and resolution. In other words, first you find out if you have a collision and then you do something about it. In your case you want to move the player out of the floor/wall/whatever.
That CheckCollision function is only the detection part.
Exactly, just do something like
or some such. and then detect if it's true or not with the help of boundingbox.
Re: Changing to Collision?
Posted: Wed Jan 25, 2012 11:44 pm
by AwkwardOrpheus
I seem to be still having a problem with collision because the tutorial is using solid objects, I'm using images -
http://pastebin.com/QrWkuxwc
Still quite new with lua ;?
Re: Changing to Collision?
Posted: Fri Jan 27, 2012 8:50 pm
by Kadoba
What do you mean by solid objects?
Your collision system right now is just basically not letting the player go below a certain point so it appears you have a floor.