contact box

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
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

contact box

Post by elsalvador »

Can someOne help me solve this small problem..
my collision fails!! when they are in contact they work using one button but
if use 2 buttons at same time it fails?
Goal is: don't want the box to go through the other at all!
Attachments
2boxes.love
(3.29 KiB) Downloaded 190 times
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: contact box

Post by kraftman »

The problem is probably that you're storing the direction the player is moving in a single variable, so if they are moving both down and left then only one of those things will be assigned to l.s and checked against foe.

I'd recommend moving the collision detection of the player into the player file, scrapping the direction storage and instead just work out a new x and y coordinate, and then calculating if that new position would result in a collision with any object.

Also bear in mind that code is read a lot more than it is written, it might seem easier and quicker to write variables like "l.s" but when things get more complex, or when you come back to the code a month later, you'll wish you'd used "player.direction". As a bonus searching for "player" will return a much narrower set of results than "l"
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: contact box

Post by elsalvador »

I'd recommend moving the collision detection of the player into the player file, scrapping the direction storage and instead just work out a new x and y coordinate, and then calculating if that new position would result in a collision with any object
So what is the difference? having it under player? and not under foe.file????
I am confuse now!
Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests