Hi,
I'm trying to get a good backspin and topspin effect on a 2d circle (pretending to be a ball) in a top down view. At the moment, I am firing my circle body using a linearvelocity and then applying an impulse to the circle body in my tick method, which is a factor of the original velocity. The impulse factor and velocity of the circle reduce over time to slow it to a stop. The impulse is applied in the direction of the initial velocity for topspin and in the opposite direction for backspin.
Apply the initial velocity:
Then in my tick method:
.h
The result I get for backspin is, with a small impulse factor the circle heads off at the set velocity, the impulses slow it down a bit and as the impulse figure reaches 0, before the velocity figure does, the circle then 'rolls' on a bit further. This seems accurate enough - the backspin is strong enough to slow the circle, but not to reverse it's direction or stop it. With a medium impulse, where the impulse and velocity reach 0 at about the same time, the circle speeds off and stops dead, suddenly, which looks a bit odd and with a high impulse the velocity reaches 0 before the impulse meaning the circle reverses direction. This looks about right, but the problem is, I think that if there is a large velocity and impulse the circle should be able to move quite a long way before it reverses direction, but no matter what the velocity the big impulse kicks in so the circle never moves very far before reversing direction. I could perhaps set the impulse to start after a specific period, but this doesn't seem right.
I was wondering if anyone had any thoughts on how I could get a decent back and top spin effect? I feel I'm perhaps halfway there with what I've done so far.
Thanks for any help.
I'm trying to get a good backspin and topspin effect on a 2d circle (pretending to be a ball) in a top down view. At the moment, I am firing my circle body using a linearvelocity and then applying an impulse to the circle body in my tick method, which is a factor of the original velocity. The impulse factor and velocity of the circle reduce over time to slow it to a stop. The impulse is applied in the direction of the initial velocity for topspin and in the opposite direction for backspin.
Apply the initial velocity:
Code:
b2Vec2 initialVelocity;
initialVelocity.x = 5.0;
initialVelocity.y = 5.0;
circleBody->SetLinearVelocity(initialVelocity);
initialVelocity.x = 5.0;
initialVelocity.y = 5.0;
circleBody->SetLinearVelocity(initialVelocity);
Then in my tick method:
Code:
tempImpulse.x = initialVelocity.x * 0.8; //change the figure depending on impulse force required
tempImpulse.y = initialVelocity.y * 0.8;
circleBody->ApplyLinearImpulse(-tempImpulse, circleBody->GetWorldCenter());
circleBody->SetLinearDamping(0.5); //change the figure depending on rate of velocity reduction required
tempImpulse.y = initialVelocity.y * 0.8;
circleBody->ApplyLinearImpulse(-tempImpulse, circleBody->GetWorldCenter());
circleBody->SetLinearDamping(0.5); //change the figure depending on rate of velocity reduction required
.h
Code:
b2Vec2 tempImpulse;
The result I get for backspin is, with a small impulse factor the circle heads off at the set velocity, the impulses slow it down a bit and as the impulse figure reaches 0, before the velocity figure does, the circle then 'rolls' on a bit further. This seems accurate enough - the backspin is strong enough to slow the circle, but not to reverse it's direction or stop it. With a medium impulse, where the impulse and velocity reach 0 at about the same time, the circle speeds off and stops dead, suddenly, which looks a bit odd and with a high impulse the velocity reaches 0 before the impulse meaning the circle reverses direction. This looks about right, but the problem is, I think that if there is a large velocity and impulse the circle should be able to move quite a long way before it reverses direction, but no matter what the velocity the big impulse kicks in so the circle never moves very far before reversing direction. I could perhaps set the impulse to start after a specific period, but this doesn't seem right.
I was wondering if anyone had any thoughts on how I could get a decent back and top spin effect? I feel I'm perhaps halfway there with what I've done so far.
Thanks for any help.