Dynamic Body Stop Moving

Thank you Brent,

so, my player can stay exactly in the center, it doesn’t have to move around.

Just like Pokémon or Zelda :slight_smile:

Philippe

http://www.youtube.com/watch?v=38JFKza55oo&feature=youtube_gdata
There you go!

Here is the link :slight_smile:

thanks alot Brent

Hi @philippe,

The video is locked (marked as “private”). Can you please unlock it or upload a public version?

Thanks.

Done!

The video is now as a public version :slight_smile:

Hi Phillippe,

Thanks for unlocking the video. I’m curious now, how are you moving all of these objects? Are you shifting the entire display group that they’re in? I notice around 6 seconds into the video, the box passes through the bottom wall. This leads me to think you’re moving the walls as an entire display group by shifting its X and Y position independently of the player. Is this true? That practice isn’t allowed, at least in terms of maintaining the collision system properly. There are workarounds, but it’s just something to be aware of.

Brent

Yes you are right!

So how could I do it?

Thank you so much Brent,

Philippe

Should I give you all my code?

Hi Philippe,

Basically, when it comes to collisions, you need to keep all objects in the same “coordinate space” based on (0,0). You can certainly move the entire world around as an entire unit, but you can’t move different display groups around independently of each other. For example, if your “walls” are in one group, and your “player” in another, moving “wallsGroup” to 50,50 while “playerGroup” remains at 0,0 will cause collisions to malfunction (the player will consider that the walls existed in their original 0,0 coordinate space).

There are various ways around this, but it depends on the gameplay. Can your player object stay exactly centered, or does it need to move around a bit?

Brent

Hi @phillippe,

In this case, if you’re moving your entire world using a Runtime listener (shifting the X and Y of the group), you should be able (in the same code block) to just offset the player in the opposite factor of the world shift. For example, if you shift the world group by x+1 and y+1, just do the inverse on the character:

[lua]

local shiftX = 1 ; local shiftY = 1

myWorldGroup.x = myWorldGroup.x + shiftX

myWorldGroup.y = myWorldGroup.y + shiftY

character.x = character.x + (shiftX * -1)

character.y = character.y + (shiftY * -1)

[/lua]

(This code isn’t the most efficient thing possible, but you get the idea). :slight_smile:

Brent

Thank you Brent,

so, my player can stay exactly in the center, it doesn’t have to move around.

Just like Pokémon or Zelda :slight_smile:

Philippe

Thanks alot !

You answered my question thank you very much!

Phil

Hi @phillippe,

In this case, if you’re moving your entire world using a Runtime listener (shifting the X and Y of the group), you should be able (in the same code block) to just offset the player in the opposite factor of the world shift. For example, if you shift the world group by x+1 and y+1, just do the inverse on the character:

[lua]

local shiftX = 1 ; local shiftY = 1

myWorldGroup.x = myWorldGroup.x + shiftX

myWorldGroup.y = myWorldGroup.y + shiftY

character.x = character.x + (shiftX * -1)

character.y = character.y + (shiftY * -1)

[/lua]

(This code isn’t the most efficient thing possible, but you get the idea). :slight_smile:

Brent

Thanks alot !

You answered my question thank you very much!

Phil