Page 2 of 2

Re: Collision (Need Help)

Posted: Mon Mar 04, 2013 10:30 pm
by Hexenhammer
TheScriptan wrote:Here is .love file, maybe you can find out what is wrong with if, because still can't find it, i used rectangle object only in game.lua :(
Okay, found it (as promised! :) ).

Just change the beginning of game.lua to this:

Code: Select all

rectangle = {
		{x = 0, y = 0, w = 128, h = 128},
		{x = 400, y = 300, w = 128, h = 128}
	}

function game_load()
 -- definition of rectangle used to be here
end
I don't have time to analyze what exactly went wrong here but my spontaneous guess is that Lua thought "rectangle" is no longer needed and thus garbage collected it. I am not familiar with the garbage collection rules for globals.. because I never use them. Seriously, globals are evil, vicious beasts. Slay 'em all! :halloween:

Re: Collision (Need Help)

Posted: Tue Mar 05, 2013 2:55 pm
by TheScriptan
What can I say, YOU ARE MY HERO! :awesome:

Re: Collision (Need Help)

Posted: Tue Mar 05, 2013 2:59 pm
by TheScriptan
After changing that, I got another problem, I don't know how to make that rectangle a wall, what code I need to put in that If statement? :huh:

Re: Collision (Need Help)

Posted: Wed Mar 06, 2013 8:53 am
by Pash
What do you mean you want to make that rectangle a wall?

I cant see your source at work but I'm assuming you are performing simple bounding boxes collision detection. There are two elements to collision detection 1) Detection (check) 2) Resolution (not sure if checked).

ie. Player is moving, check if collision is true, if true perform action:-

Code: Select all

if Check_Collision(args) then
list actions
end
An action might be to set Player.x to Player.x - 1 or something.

Re: Collision (Need Help)

Posted: Wed Mar 06, 2013 2:33 pm
by TheScriptan
What I need to do when I collide, here is my answer, when I did that player.x = player.x - 1 and for Y it just glitched out :?

Re: Collision (Need Help)

Posted: Wed Mar 06, 2013 3:13 pm
by Pash
Thats not an answer. You are using the example detection Resolution I gave you. Not what your desired effect is.

You need to think about these elements:-

1) What will collide with your wall.
2) What you want to happen on detection of a collision with that wall to that object.

Ohh, and telling us something has "glitched out", isnt very helpful. Post your code you have modified and even the .love file. Im still at work so I cant open the love files but still, i could take a look later if someone else doesnt.

Cheers,

Pash

Re: Collision (Need Help)

Posted: Fri Mar 08, 2013 8:30 pm
by TheScriptan
So, I made a basic collision but it is very glitchy, when i collide with the wall its start flickering and movement dont work as usual then collide, here is .love file :huh:

Re: Collision (Need Help)

Posted: Fri Mar 08, 2013 10:22 pm
by Zeliarden
You should test your .love file before posting it. A .love is a renamed .zip not .rar

Re: Collision (Need Help)

Posted: Fri Mar 08, 2013 10:29 pm
by TheScriptan
Tested it, same problem, and what do you mean, rar or zip. Is there any difference to compress somehow? :shock:

Re: Collision (Need Help)

Posted: Fri Mar 08, 2013 10:32 pm
by TheScriptan
Ohhh, I see that there is a differencem thanks for noticing that, i will readd that file right now. :crazy: