ApplyTorque

i have spend countless hours on it now and I'm still convinced that i should be relatively simple but it just keeps on making all kinds of errors.
is there someone out there who can explain i simple words how i can make my ball move via the ApplyTorque(); pleeeeeeease?

this is the code for creating the ball:

playerDef = new b2BodyDef();
circleDef = new b2CircleDef();
circleDef.radius = 50;
circleDef.density = 1.0;
circleDef.friction = 0.5;
circleDef.restitution = 0.5;
playerDef.position.Set(290,450);
playerDef.AddShape(circleDef);
playerDef.userData = new PlayerClass();
playerDef.userData.width = circleDef.radius * 2;
playerDef.userData.height = circleDef.radius * 2;
addChild(playerDef.userData);
m_world.CreateBody(playerDef);
try some version of this 🙂


Code:

var body:b2Body;

playerDef = new b2BodyDef();
circleDef = new b2CircleDef();
circleDef.radius = 50;
circleDef.density = 1.0;
circleDef.friction = 0.5;
circleDef.restitution = 0.5;
playerDef.position.Set(290,450);
playerDef.AddShape(circleDef);
playerDef.userData = new PlayerClass();
playerDef.userData.width = circleDef.radius * 2;
playerDef.userData.height = circleDef.radius * 2;
addChild(playerDef.userData);

body = m_world.CreateBody(playerDef);
body.ApplyTorque(1000000);


all we are doing is creating a reference of the b2Body created when you call the m_world.CreateBody method. Then we can use the ApplyTorque on that body. With the default settings in b2Settings.as you'll need to use a pretty big number to get an effect from just calling it once.
You are trying to make the ball spin right? Otherwise you should use ApplyImpulse to make it actually move.
thanx 😀 i finnaly get it...but i have one more question...

when i use ApplyImpulse i adds movement to the body's current movement witch means it keeps on accelerating so if i want the body to move the opposed direction i have decelerate before moving. is there a way of manipulating or setting the impulse to 0 ?
I think you may be able to set linear velocity directly, just look for some property like that. Otherwise you just have to get the linear velocity and apply an equal but opposite impulse to stop it. You could make that into a stop object function for convenience.

Original thread: https://box2d.org/forum/viewtopic.php?t=440