1
\$\begingroup\$

I'm seeking information on how to implement something. I have a ball on a moving platform. The ball has a position and momentum.

Here's a gif illustrating the situation:
enter image description here

So the way it works is, the ball detects when it touches a specific platform, and "childs" itself to that platform. When the platform moves, it will go through all its children and move them by the same amount.

My problem is, when the ball moves on a platform, it should accumulate momentum from the motion of the platform-- which should be visible when the platform slows down (or in some cases stops abruptly)

I've tried several things but always end up with an accelerating ball that zooms off in the direction of the platform. I've tried subtracting the component of the ball's momentum from the momentum that is going to be added but I still get an accelerating effect. In fact everything I try gives me acceleration in the direction of the platform's motion.

Can anyone explain to me what the right way is to deal with this problem?

      • Edit to add some clarification:

In the interests of making this run on slower devices, the ball's physics are not complicated. The ball's main loop is a glorified version of mPosition+=mMomentum, with the player able to change the momentum.

When a ball is on a platform, all that happens is, the platform says "I moved n, therefore Ball->mPosition+=n" ... but I would be interested in hearing the "right" way to do this so that I can try to adapt it in such a way that it doesn't require a full hardcore physics simulation to run.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ does increasing the friction on the ball and platform work? \$\endgroup\$
    – Pow
    Feb 28 at 23:35
  • \$\begingroup\$ In the interests of making this playable on slower machines, the physics is not complicated. The ball's friction is just a multiplier on its momentum. I'm looking for a way to simulate the effect, not run full physics on it. \$\endgroup\$ Feb 29 at 11:18
  • \$\begingroup\$ My mistake, I thought you were using Unity. \$\endgroup\$
    – Pow
    Feb 29 at 13:38
  • \$\begingroup\$ How slow of a machine are you trying to run it on? Any computer or console made in the last 10 or 15 years should have more than enough processing power to run a physics engine for a simple scene like this. Even smartphones can handle physics as long as there aren't too many objects being simulated at once. Are you planning to have hundreds of balls moving around simultaneously? \$\endgroup\$
    – Kevin
    Mar 2 at 2:24

1 Answer 1

1
\$\begingroup\$

Other than the mentioned friction on the sphere body you could try looking into matrix multiplication. Transform the sphere matrix with the platform matrix then setting the resulting velocity vector to whatever it was before that matrix multiplication. You could also try simply adding the velocity vector of the platform to the sphere when it detects that it no longer collides. Good luck with your game.

\$\endgroup\$
4
  • \$\begingroup\$ When I do this, what I end up getting is a cumulative increase in the ball's momentum in the direction of the platform. I tried to cancel that by subtracting components before applying it, but I still get the ball accelerating in the direction of the platform's movement, whereas the desired effect is to not be able to "speed up" per se. \$\endgroup\$ Feb 29 at 11:20
  • \$\begingroup\$ Maybe you should not try to write your own momentum math and just purely use things like friction, matrix transforms and by resetting things like (angular) velocity. \$\endgroup\$
    – mouse
    Mar 1 at 13:28
  • \$\begingroup\$ I'd be willing to do that... but I'm unfamiliar with what the exact process would be. Like specifics, I mean. Do you have a link? \$\endgroup\$ Mar 1 at 17:53
  • \$\begingroup\$ You may be making things harder than they have to be. Assuming you’re using a physics library you should be able to use some basic form of matrix transforms, setting friction and setting velocity. Friction will be ideal. \$\endgroup\$
    – mouse
    Mar 5 at 17:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .