Character movement on collision problem

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.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Character movement on collision problem

Post by coffee »

Ellohir wrote:The usual first approach to collision resolution is "if the player enters a wall, push it out quickly". It works, but that makes it really ugly. What you want is to, in one only function, decide if the player can move or not. Doing so, the player is never "inside" the wall. You move the player where it wants, test collision, and let it be or return to previous position.
I agree. A dedicated function is the proper way to not only detect obstacles and avoid that moves but check also for check first other special things like enter traps, fall in holes, enter in portals, some object interactions and made respective function re-route).
MiniDemonic
Prole
Posts: 28
Joined: Tue Mar 20, 2012 10:39 am

Re: Character movement on collision problem

Post by MiniDemonic »

That code, produced the same error when walking against a wall, maybe I did something wrong when modifying it for my code, but I think I found a solution.
I will add 4 invisible objects around the player, if these objecs touches a wall the corresponding direction on the keyboard is disabled. This is simple but could produce a perfomance hit I think. When I get my idea working I will add a new .love for you to see, as it is proper manners to provide the solution for a problem if found.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Character movement on collision problem

Post by tentus »

This is sometimes called the "white cane" solution. You can save performance by only having one cane, and positioning it in front of the player (based on the direction they are facing). It's not the greatest solution in terms of performance, but it's easy to wrap your head around, which is a plus.
Kurosuke needs beta testers
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 161 guests