RPG-Style Movement

I am sure this has been covered somewhere, I just have yet to find it. I am trying to put together the makings of a small RPG, but am having trouble with the player character movement system. I am using 4 buttons to move the character, but cannot get the character to not walk through walls and objects.

When using the playerChar.x = whatever type movement, he will just walk through walls and objects. When using a physics:applyLinearImpulse type movement, I cannot make him go a short distance. No matter what I set the impulse to, he flies off into oblivion. My initial thoughts went to using the direct x/y movement of the character, but having some sort of display grouping set up that if that x/y was going to hit something in the group, it would negate moving in that direction. Haven’t figure out how to accomplish that yet, though.
 

I know this is likely an easy fix, I just must not be searching for the right thing. Any help would be greatly appreciated.

Hi @se_nperryman,

Is your control input something like a 4-directional gamepad, where the user holds down on a direction to move, and the movement stops when the user un-presses? If this is the case, you should probably consider using “setLinearVelocity()” instead of applying an impulse, to move the player at a constant rate. Then, on de-press, just stop the linear velocity (0,0 values).

If you’re doing something like a tap-to-move scheme, this is possible but a bit more tricky. I’ve accomplished this in a game by setting just the right amount of linear impulse + linear damping, such that the player “dashes” a short distance and stops moving (approximately) at the place the user tapped. I also implemented a constant touch-follow in the same function, so the user can drag the touch around and the player will follow it. Mostly, it involved a fair amount of experimentation to get the player moving at the correct rate depending on the impulse, the mass of the body, the distance between the player and the touch, etc… but it is possible.

Hope this helps,

Brent

Currently it is just 4 buttons, that the user would tap to move a set distance. Using the game pad style where you hold it down might work though, I will look into it. Both of the solutions you proposed seem very plausible for what I am doing, thanks for getting back to me so quickly!

Hi @se_nperryman,

Is your control input something like a 4-directional gamepad, where the user holds down on a direction to move, and the movement stops when the user un-presses? If this is the case, you should probably consider using “setLinearVelocity()” instead of applying an impulse, to move the player at a constant rate. Then, on de-press, just stop the linear velocity (0,0 values).

If you’re doing something like a tap-to-move scheme, this is possible but a bit more tricky. I’ve accomplished this in a game by setting just the right amount of linear impulse + linear damping, such that the player “dashes” a short distance and stops moving (approximately) at the place the user tapped. I also implemented a constant touch-follow in the same function, so the user can drag the touch around and the player will follow it. Mostly, it involved a fair amount of experimentation to get the player moving at the correct rate depending on the impulse, the mass of the body, the distance between the player and the touch, etc… but it is possible.

Hope this helps,

Brent

Currently it is just 4 buttons, that the user would tap to move a set distance. Using the game pad style where you hold it down might work though, I will look into it. Both of the solutions you proposed seem very plausible for what I am doing, thanks for getting back to me so quickly!