Physics - Imposing speed limit on body

Hi all,

How do I limit the speed of my character?

I am doing as below, but it forces my Y-Velocity to be 0 because I can’t find any functions to set just the X-Velocity. This means when the object is supposed to fall, it doesn’t.

if(playerTopSpeed \< playerVelocityX) then  
 player:applyForce(100, 0, player.x, player.y);  
else  
 player:setLinearVelocity(playerTopSpeed, 0, player.x, player.y);  
end  

Is there a better way to move a character in a constant speed without diminishing the physics?

I did X = X + 1, but the collisions don’t work well with that.

Thanks. [import]uid: 75783 topic_id: 12466 reply_id: 312466[/import]

You could move it without using physics at all, which is easy to make a constant speed - but assuming you want/need physics then you need to check this out;
http://developer.anscamobile.com/content/game-edition-physics-bodies#body:getLinearVelocity

You can get the linear velocity and use that rather setting the Y at zero :slight_smile:

Peach [import]uid: 52491 topic_id: 12466 reply_id: 45596[/import]

Yea tried it without physics but the collisions were slow to react.

I did try applying the Get-y to the function but the character lifted off and flew off the screen… I guess it might be something wrong with my game logic. Would be easier if a function was provided to set a single property. [import]uid: 75783 topic_id: 12466 reply_id: 45605[/import]

Yea tried it without physics but the collisions were slow to react.

I did try applying the Get-y to the function but the character lifted off and flew off the screen… I guess it might be something wrong with my game logic. Would be easier if a function was provided to set a single property. [import]uid: 75783 topic_id: 12466 reply_id: 45606[/import]

If it’s flying off when it wasn’t previously then it’s a (probably simple) coding error; try troubleshooting a little - you should be able to get your character moving how you want :slight_smile: [import]uid: 52491 topic_id: 12466 reply_id: 45774[/import]