Movement and Collision: how do you do both?

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
User avatar
sanjiv
Citizen
Posts: 88
Joined: Mon Feb 27, 2012 5:11 am

Movement and Collision: how do you do both?

Post by sanjiv »

What's the best way to do this? What's the basic concept?

a) Move from position A to position B IF AND ONLY IF position B isn't a collision(with an impenetrable object)?
b) Move from position A to position B, and if position B is a collision, then re-adjust?
c) something else?

QUESTION 2: should a movable agent
a) have the same movement function applied to him at all times?
b) have various states, and have different movement functions for those various states? I.e. if it's in the air, on the ground, clinging to a wall, etc?

What's worked for you in the past? Ultimately I want to start collaborating, and I figure there are "best practices" out there.
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Movement and Collision: how do you do both?

Post by substitute541 »

Question 1 :
The simplest, though not extremely accurate, but fine for most cases, is (b).

Question 2 :
Depends. I will go with (a), for simple games, but for complex platformers, like those with a sticky floor and walls, and a blowing wind, I will go with (b).
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Movement and Collision: how do you do both?

Post by Inny »

B. The basic idea is that you take the bounding rect of the player, and the movement vector, and keep trying to apply the X component to that base bounding rect, to see what the rect collides with. If it collides, then subtract from the X component how much the collision overlap was. Then reapply for the next one. It's considered a valid movement when everything has been accounted for (and you use some kind of Broadphase step to pare down how many other things need to be analyzed). Then you do it again for the Y component. The reason you separate them is to prevent things like unintentional sticking to walls and catching on internal borders between objects. The tell tale sign of the X and Y components being separated during collision detection is that you can "slide" along a wall as you move towards it.

As for different movement styles between ground and air, that's a Game Mechanic, meaning that your game is what you decide here. Some games use the same control scheme for both (Megaman, for instance) where as others will change your motion between various modes (Castlevania).
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests