I'm trying to make a function for a skydiving game that'll make a sprite rotate left/right and then move that way depending on how angled it is, at least i would be if the object's get world centre parameter was recognised, code is as follows:
Dynamic circle creation:
function defineNewDynamicCircle(density, friction, restitution, x, y, r, objid) {
var fixDef = new b2FixtureDef;
fixDef.density = density;
fixDef.friction = friction;
fixDef.restitution = restitution;
var bodyDef = new b2BodyDef;
bodyDef.type = b2Body.b2_dynamicBody;
bodyDef.position.x = x / SCALE;
bodyDef.position.y = y / SCALE;
// This creates a new circle shape
fixDef.shape = new b2CircleShape(r/SCALE);
var thisobj = world.CreateBody(bodyDef).CreateFixture(fixDef);
thisobj.GetBody().SetUserData({id:objid})
return thisobj;
}
object initialisation:
var capsule = defineNewDynamicCircle(1.0,0.2,0.8,400,400,20,"capsule");
problematic function:
function bankleft() {
capsule.GetBody.ApplyImpulse(new b2Vec2(-0.5,0), capsule.GetBody.GetWorldCenter());
if(capsule.GetBody.GetLinearVelocity().x < -5) {
capsule.GetBody.SetLinearVelocity(new b2Vec2(-5,capsule.GetBody.GetLinearVelocity().y));
}
}
Thanks for any insights you can provide!