Approach to handling player movement in platformer style game?

I’m developing a platformer prototype and am not yet satisfied with the feel of the movement I’ve gotten for my player character. Clearly controls have to feel great for this type of game!

I’ve been staring at this long enough that I’m starting to confuse myself regarding the best approach.

Does anyone have advice on how to set up great movement for the player in a platformer game? Does anyone know of any great samples that are out there?

It seems best to use player:applyLinearImpulse() for handling jumping.

I’m not getting great overall results for left and right movement. I can’t decide if I should use player:applyForce() or player:setLinearVelocity().

I am using the physics API to be able to take advantage of gravity and collisions.

Do you recommend that I keep everything frictionless and build damping into the movement system (iteratively reducing velocity/force once move input is removed)? Or should I use friction between platform and player to reduce velocity and stop movement once movement input is remvoed?\

Thanks for any tips anyone has :slight_smile: [import]uid: 105707 topic_id: 32183 reply_id: 332183[/import]

Hi EHO,

If I were tackling this, I would opt for setting linear velocity, not applying force or impulse, because the former sets a consistent value, while the latter methods factor in a force to the object which might already be moving. In terms of the X value for linear velocity, I imagine that must depend on how fast the player is moving… if the player is running fast, I guess you should get the current X velocity and then use that as the parameter for the jump’s X velocity too.

If you want “perfect” movement, I think you’ll need to build some kind of behind the scenes monitoring method… from a dead stop, player movement left or right would increase gradually, but still use the application of a direct linear velocity.

My overall point is, applying force and impulses in Box2D can be unpredictable and you shouldn’t rely on it for consistent, controlled movement. Setting linear velocity gives you more control, but if course, might be better monitored and modified by various if-then conditions.

Brent [import]uid: 9747 topic_id: 32183 reply_id: 128117[/import]

Hi EHO,

If I were tackling this, I would opt for setting linear velocity, not applying force or impulse, because the former sets a consistent value, while the latter methods factor in a force to the object which might already be moving. In terms of the X value for linear velocity, I imagine that must depend on how fast the player is moving… if the player is running fast, I guess you should get the current X velocity and then use that as the parameter for the jump’s X velocity too.

If you want “perfect” movement, I think you’ll need to build some kind of behind the scenes monitoring method… from a dead stop, player movement left or right would increase gradually, but still use the application of a direct linear velocity.

My overall point is, applying force and impulses in Box2D can be unpredictable and you shouldn’t rely on it for consistent, controlled movement. Setting linear velocity gives you more control, but if course, might be better monitored and modified by various if-then conditions.

Brent [import]uid: 9747 topic_id: 32183 reply_id: 128117[/import]

Brent, I appreciate your insight.

I’ve used setLinearVelocity() to good effect in another prototype (top down 2D game) so what you suggest makes sense given my challenge with the apply force and impulse functions.

Good point that I could use the getLinearVelocity() function at the start of a jump to determine the x velocity going into it.

So it seems that I might need to craft a function that can look at the velocity of the player on a frame by frame basis and then increase or decrease velocity as appropriate?

Has anyone come across a code sample that does platformer player movement well?

Thanks :slight_smile:

[import]uid: 105707 topic_id: 32183 reply_id: 128293[/import]

Hi EHO,
Good to hear these new ideas might help you figure it all out!

A function that constantly monitors the X velocity (prior to a jump) isn’t necessary. You should just be able to get the X velocity… local vx, vy = player:getLinearVelocity() … and then use that vx value to set the same linear X speed on the jump (with, of course, a fairly sharp upward Y velocity).

I did just notice a small platformer tutorial (link below), but I haven’t read it through. It might be what you’re looking for, or maybe not quite, but it also might give you some new ideas.

http://thatssopanda.com/developing-a-game-with-corona-sdk/

Brent
[import]uid: 9747 topic_id: 32183 reply_id: 128299[/import]

Brent, I appreciate your insight.

I’ve used setLinearVelocity() to good effect in another prototype (top down 2D game) so what you suggest makes sense given my challenge with the apply force and impulse functions.

Good point that I could use the getLinearVelocity() function at the start of a jump to determine the x velocity going into it.

So it seems that I might need to craft a function that can look at the velocity of the player on a frame by frame basis and then increase or decrease velocity as appropriate?

Has anyone come across a code sample that does platformer player movement well?

Thanks :slight_smile:

[import]uid: 105707 topic_id: 32183 reply_id: 128293[/import]

Hi EHO,
Good to hear these new ideas might help you figure it all out!

A function that constantly monitors the X velocity (prior to a jump) isn’t necessary. You should just be able to get the X velocity… local vx, vy = player:getLinearVelocity() … and then use that vx value to set the same linear X speed on the jump (with, of course, a fairly sharp upward Y velocity).

I did just notice a small platformer tutorial (link below), but I haven’t read it through. It might be what you’re looking for, or maybe not quite, but it also might give you some new ideas.

http://thatssopanda.com/developing-a-game-with-corona-sdk/

Brent
[import]uid: 9747 topic_id: 32183 reply_id: 128299[/import]