Page 1 of 1

How to make your character collide with terrain

Posted: Sat Dec 22, 2012 12:54 am
by n1ghtk1n9
How can I make my character not collide with the terrain? This is probably a noob question, but I started Love just yesterday.
Also how can I make an image not able to pass through. To elaborate, if I had a tree image in the middle of my screen, how can I make it so if I move my character/player up to that image, it couldn't/wouldn't pass through it?
Links to Code
main: http://pastebin.com/GQ8M8bJ7
world: http://pastebin.com/kEKkEdav
player: http://pastebin.com/7ckikz9x

Sorry if its hard to understand, I'm horrible at explaining things.

Re: How to make your character collide with terrain

Posted: Sat Dec 22, 2012 5:45 am
by Spec0pAssassin
If you could, could you post a .love of what you're working on. A quote from the rules on posting
Give us a .love of your game. This allows us to find the error, see it in context and possibly try out some candidate solutions.
But I get what you're asking, you want your player to collide with the tree and not pass through right? As if you were to walk into a tree in real life?

Re: How to make your character collide with terrain

Posted: Fri Jan 04, 2013 4:55 am
by n1ghtk1n9
Spec0pAssassin wrote:If you could, could you post a .love of what you're working on. A quote from the rules on posting
Give us a .love of your game. This allows us to find the error, see it in context and possibly try out some candidate solutions.
But I get what you're asking, you want your player to collide with the tree and not pass through right? As if you were to walk into a tree in real life?
I was going to provide a .love, but it would be quite useless, since it's quite self-explanatory what happens(the guy passes through the tree)

Re: How to make your character collide with terrain

Posted: Fri Jan 04, 2013 11:11 pm
by mathacka
You need a collision function -- something that will compare two rectangles and see if they intersect, here's some pseudocode:

Code: Select all

Function Collision(x0,y0,w0, h0, x2, y2, w2, h2)
     If x0 > (x2 + w2) Or (x0 + w0) < x2 Then Return False
     If y0 > (y2 + h2) Or (y0 + h0) < y2 Then Return False 
     Return true
End