I been reading about RK4 for physics implementation in a game, so I read in some pages and all people recommend me this page:


This page shows clearly how this one works, but I can't figure out how to implement in my game, maybe I don't understand that good but I find some things that are not really clearly to me.

In my game, the player decides when change direction in the X-Axis but I can't figure out how with this RK4 implementation change the direction of the object, in the example the point goes side to side but I don't understand how I can control when he goes right or left.

So if anyone can give a little bit of clarity in this implementation and my problem which I do not understand I will be really grateful.

Thanks beforehand


To be frank: RK4 almost certainly isn't your biggest need right now. What's more, unless you're after very accurate game physics, I recommend against using Runge-Kutta entirely - it's simply more complication, and for most platformers standard Euler integration should be more than enough. In fact, most platformers don't really need that sort of physics at all - if you're looking to try and control character position, I would suggest 'faking it' by giving the character a constant velocity while the keys are down, with simple acceleration to speed (increase the velocity by a constant amount each tick until maximum speed is reached) and the inverse (deceleration to 0) when the key is released. What's the core problem that you're trying to solve?

  • \$\begingroup\$ Thanks for the answer, there is no main problem to solve only that we trying to give the game a more realistic motion to the movement of the player, so you recommend use a kind of Euler integrator in this case when a really good accuracy it's not neccesary? \$\endgroup\$ – oscar.rpr Nov 25 '11 at 14:16
  • \$\begingroup\$ It's hard to say without knowing more about the specific game, but if you're trying to specifically make the player look realistic in motion then that's closer to an animation problem than a physics problem per se. \$\endgroup\$ – Steven Stadnicki Nov 25 '11 at 17:03
  • \$\begingroup\$ No, the animation looks fine, here is a video recorded months ago, youtube.com/watch?v=-tlXg-yyoVA, we just want to give a more realistic sensation of acceleration like New Super Mario Bros or Rayman Origins. \$\endgroup\$ – oscar.rpr Nov 25 '11 at 21:23
  • \$\begingroup\$ @oscar.rpr : how much does that video look like the current state of your animation, and do you have anything more recent? That actually just reinforces my impression that the issue is in animation, and not physics: the character's animation is largely divorced from their actions for the most part (e.g., there's no animation for the character turning around or even really slowing down, nothing showing the character crouching in preparation for a jump, etc). In my experience, that sort of polish will affect your perceived physics more than almost any amount of 'real' physics will. \$\endgroup\$ – Steven Stadnicki Nov 28 '11 at 20:46
  • \$\begingroup\$ Yes, we have something more recently but the team decides not updated yet until some things are fixed. Some things of animation are corrected but not many. Yes, that kind of animation doesn't exist because the current system of movement doesn't have a system of acceleration, so an animation of slowing down it's not yet, and the animation for turning around we didn't think about that. But adding acceleration to the game instead of constant speed will not help us to give a little bit of realism even so without the extra animations? \$\endgroup\$ – oscar.rpr Nov 29 '11 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.