Changing to Collision?

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
AwkwardOrpheus
Prole
Posts: 4
Joined: Wed Jan 25, 2012 5:59 pm
Location: United Kingdom

Changing to Collision?

Post 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?
Attachments
test.love
A simple test, all the backgrounds and stuff were merely used off google images to rush the code for now, but I can get them done later in Photoshop.
(1.6 MiB) Downloaded 119 times
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: Changing to Collision?

Post by baconhawka7x »

I don't understand what you are asking, it looks like your collision works just fine.
AwkwardOrpheus
Prole
Posts: 4
Joined: Wed Jan 25, 2012 5:59 pm
Location: United Kingdom

Re: Changing to Collision?

Post 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.
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: Changing to Collision?

Post 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
AwkwardOrpheus
Prole
Posts: 4
Joined: Wed Jan 25, 2012 5:59 pm
Location: United Kingdom

Re: Changing to Collision?

Post 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)
?
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Changing to Collision?

Post 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.
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: Changing to Collision?

Post 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

Code: Select all

is_collided = false
or some such.
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: Changing to Collision?

Post 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

Code: Select all

is_collided = false
or some such. and then detect if it's true or not with the help of boundingbox.
AwkwardOrpheus
Prole
Posts: 4
Joined: Wed Jan 25, 2012 5:59 pm
Location: United Kingdom

Re: Changing to Collision?

Post 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 ;?
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Changing to Collision?

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 59 guests