Hi
How to reduce the speed of the body speed gradually. If i use the code like this
circleBody.SetAngularVelocity(0)
It stops the body suddenly but i want the speed will reduce gradually and it should stop moving.
And i do not know how to use the SetLinearVelocity for this. Help me out to do the correct way.
You could apply a small angular impulse or torque in the opposite direction to the current rotation. Just take the negative of the current angular velocity, and multiply it by a small number that suits your needs 🙂
Thanks for your reply. It works 🙂
One more question i little bit confused at what time we can use SetAngularVelocity, SetLinearVelocity(), ApplyForce and ApplyImpulse etc.
Can you explain me??
Any time except for inside a call to b2World::Step.
Get Angle() value is showing randomly like 360, 350, 300 ,250.. while the body rotation.
What is the reason for this random angle?
I think it is because of higher speed of the body. is i'm correct?
How can i make it to decrease like 360,259,258,257,...
That doesn't look so random 😀
If a body keeps spinning in the same direction the angle can go over 360 degrees, or under 0 degrees. Maybe it has been spinning for a while?
Also remember GetAngle gives you a value in radians, not degrees.
var angle:Number=Math.round((carBody.GetAngle() * (180 / Math.PI)));
while (angle <= 0)
{
angle += 360;
}
while (angle > 360)
{
angle -= 360;
}
This is the calculation i have done to find it in degrees.
From this only i'm getting the random values i said.
leftwheelRevoluteJoint.SetMotorSpeed(7*Math.PI * (kbd.isKeyPressed(38) ? -1 : 0));
this code acts perfect. if i'm not pressing the key the motor speed is zero i have checked it by using GetMotorSpeed().
But still the object is moving. So that i checked leftwheelRevoluteJoint.GetJointSpeed() it shows values based on the speed. And it is zero if the object is not in movement.
if(front_wheel.GetAngularVelocity()>0)
{
var ang2:Number=front_wheel.GetAngularVelocity()*-0.2
front_wheel.SetAngularVelocity(ang2)
}
used this code to reduce the movement but it is not perfect to use. It stops the movement suddenly.
And my need is i want to reduce the movement fast and gradually if i'm not pressing the key.
?
This is almost exactly the same question as your first post in this thread. In the second post I gave a suggestion, and in the third post you said it worked. Why are we back to this again now? Very confusing dude.
Don't use SetAngularVelocity. Apply a torque or angular impulse.
Very Sorry. Kindly bare me.
I have two problems.
1. First one
var angle:Number=Math.round((carBody.GetAngle() * (180 / Math.PI)));
while (angle <= 0)
{
angle += 360;
}
while (angle > 360)
{
angle -= 360;
}
var getFlip:Number=Math.round(carBody.GetAngularVelocity())
if(!checkingContacts.bikeContact)
{
if(!backFlip && getFlip<=-3 && (angle>1 && angle<=50))
{
trace("back")
backFlip=true
}
if(!frontFlip && getFlip>=4 && (angle>=300 && angle<=360))
{
trace("front")
frontFlip=true
}
}
This calculation is for finding the Back or front flip of the body if it rotates full. By doing this the angle calculation is varies so that i cant find it perfect.
2.Second one
I want to reduce the bike speed gradually for that i used SetAngularVelocity but you said not to use that.
for this let me apply impulse or torque. Searching how to do it in flash.
These are my problems. Very sorry for my confusion. 🙁