Page 1 of 1

Collision not Working.. help me please

Posted: Sun May 26, 2013 1:03 am
by Pheeea
I created my own game and when i tried adding the player image the collision went all crazy

im new to programming and im kinda noobish... so help me please

Re: Collision not Working.. help me please

Posted: Sun May 26, 2013 9:22 am
by Robin
Could you upload your game as a .love? See the wiki to learn how to make a .love.

Re: Collision not Working.. help me please

Posted: Sun May 26, 2013 11:34 am
by Pheeea
2D Spel.love
(53.2 KiB) Downloaded 135 times
There it is

Re: Collision not Working.. help me please

Posted: Sun May 26, 2013 12:53 pm
by micha
I found two thing that go wrong. First, the player is drawn with an offset (a bit too far right and down). To correct this, replace the drawing command by this:

Code: Select all

love.graphics.draw(hero, player.x, player.y,0,1,1,player.w/2,player.h/2)
Second, when you hit a wall on the left, you start floating/jumping. To fix this, change line 106 in your main.lua to

Code: Select all

				self.x = nextX + map.tileWidth - ((nextX - halfX) % map.tileWidth)+1
(add +1 in the end). After a collision with the left wall, the player was not put to the correct position, such that in the next frame, the up/down-collision found a collision and moved the player up.
You have to change line 78 (collision up/down) similarly to:

Code: Select all

				self.y = nextY + map.tileHeight - ((nextY - halfY) % map.tileHeight)+1

Re: Collision not Working.. help me please

Posted: Sun May 26, 2013 1:43 pm
by Pheeea
Thank you so much for the help, but i have a question.

I want to add enemies to my game aswell as a fire mechanic and score is there any tutorial out there for it?

Re: Collision not Working.. help me please

Posted: Mon May 27, 2013 1:27 pm
by Davidobot
Pheeea wrote:Thank you so much for the help, but i have a question.

I want to add enemies to my game aswell as a fire mechanic and score is there any tutorial out there for it?
Here is a really neat tutorial: http://www.headchant.com/2010/12/31/lov ... 2-pew-pew/

Re: Collision not Working.. help me please

Posted: Wed Jun 12, 2013 8:29 pm
by jjmafiae
next time use the right forum would you :3