Collision not Working.. help me please

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Pheeea
Prole
Posts: 3
Joined: Sun May 26, 2013 12:57 am

Collision not Working.. help me please

Post 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
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Collision not Working.. help me please

Post by Robin »

Could you upload your game as a .love? See the wiki to learn how to make a .love.
Help us help you: attach a .love.
Pheeea
Prole
Posts: 3
Joined: Sun May 26, 2013 12:57 am

Re: Collision not Working.. help me please

Post by Pheeea »

2D Spel.love
(53.2 KiB) Downloaded 135 times
There it is
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Collision not Working.. help me please

Post 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
Pheeea
Prole
Posts: 3
Joined: Sun May 26, 2013 12:57 am

Re: Collision not Working.. help me please

Post 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?
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Collision not Working.. help me please

Post 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/
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Collision not Working.. help me please

Post by jjmafiae »

next time use the right forum would you :3
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests