1
\$\begingroup\$

Im trying to make a Vortex effect on a Circle Body that is a Sensor. I've been looking for this and all examples i look for are in C++ or Objective C and i dont seem to translate them well.

when my objects collition, it calls beginContact(..) and it sets a flag so that i can call bodyToUpdate.applyForce(...);

 public void beginContact(Contact contact) {
             setColliding(true);
 }

 //updating collition every frame
 public void act(){
     if (colliding) {
        ball.getBody().applyForce(....);

 }

how to calculate the amount of force to apply every frame to make it a vortex?

so i now have the object going straight to the center of the vortex, but no "spin"

public void act() {
    if (colliding) {
        ball.getBody().setLinearVelocity(0, 0);

        ball.getBody().applyForce((portal.getBody().getPosition().x - ball.getBody().getPosition().x) * i,
                (portal.getBody().getPosition().y - ball.getBody().getPosition().y) * i,
                ball.getBody().getPosition().x, ball.getBody().getPosition().y, true);

        i++;
    } else
        i = 10;
}
\$\endgroup\$
1
\$\begingroup\$

If you can make the ball travel to the center of the vortex, you have half the answer. In potential flow theory, this is known as a sink.

The other half of the answer also comes from potential flow theory, where you can make use of the irrotational vortex:

Irrotational vortex

"Irrotational vortex" by Silver Spoon is licensed under CC BY-SA 3.0

The equation describing the tangential component of the flow (relative to the vortex center) is:

tangential velocity irrotational vortex,

where r is the distance to the centre of the vortex from the point of interest, and \tau is the vortex strength (you can tune this to your particular vortex).

For each body inside the vortex, the first step is to calculate the 'flow' speed at the centre of mass of the body. But now what? You can't just set the speed of the body to that of the vortex, because then the initial tangential momentum the body had when coming into the vortex doesn't have any effect. I would instead reccomend that you use the velocity to apply a drag force. I've already spelled out how to incorporate drag in another answer of mine, so I won't regurgitate it here.

As a side note, you might want to re-implement your sink in a similar way, where the radial flow speed is given by:

source_sink velocity

This equation can easily describe a source or a sink, depending on the sign of Q.

Then you can actually just compute the vector sum on the tangential and and radial velocity components, and use the resultant velocity vector to calculate the drag force:

total velocity

To summarize, I recommend that you superimpose the sink and the vortex to achieve the whirlpool to get a resultant flow velocity at the centre of mass of each body; then use that velocity to calculate an appropriate drag force to apply to the body.

If you want to read more about potential flow, I recommend these MIT lecture notes.

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

My answer might be too shortcomed if I am missing something, but if all you want is to add additional force to spin things in a vortex way, all you need to do now is to act another force on each of the affected bodies, which goes in the tangent of the angle between it and the vortex center.

So, if angle is the radian angle between the vortex center and the body that needs to spin, v1 will be the direction vector from the center to the body, aiming at this angle: v1 = (cos(angle), sin(angle))

From v1, you compute v2 as its orthogonal vector: v2 = (v1y, -v1x) and then use v2 as a new force that accounts for spin. Be careful. if the magnitude of this spin force is too big, it can probably go outside of the vortex orbit, so make sure you balance both forces so it spins but still keeps approaching the middle of the vortex. Let me know in the comments if something is unclear.

|improve this answer|||||
\$\endgroup\$

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.