Hi guys,
So I'm fairly new to box2d, and I'm working on a platformer that's combining it with flashpunk (which is working rather well for the most part). I'm currently working on creating a moving platform, and decided to try using a prismatic joint for the task. This is the first time I've used joints, and the rest of the engine has been working fine thus far.
My problem is that no matter what I do, the object the joint is acting on seems to simply ignore the joint's parameters (gravity and other objects act on it as they would if the joint didn't exist), yet when I turn debug drawing on, the joint is clearly there and attached to the body I'm interested in.
My code is below (sorry that it's just a snippet, I've got a rather extensive set of classes going through this, and don't want to chuck it all at you unless its necessary). I'm currently ignoring the actual movement data going into the class and trying to just make it work with magic numbers before I plug real data back into it.
Any help on this would be brilliant.
Paul.
So I'm fairly new to box2d, and I'm working on a platformer that's combining it with flashpunk (which is working rather well for the most part). I'm currently working on creating a moving platform, and decided to try using a prismatic joint for the task. This is the first time I've used joints, and the rest of the engine has been working fine thus far.
My problem is that no matter what I do, the object the joint is acting on seems to simply ignore the joint's parameters (gravity and other objects act on it as they would if the joint didn't exist), yet when I turn debug drawing on, the joint is clearly there and attached to the body I'm interested in.
My code is below (sorry that it's just a snippet, I've got a rather extensive set of classes going through this, and don't want to chuck it all at you unless its necessary). I'm currently ignoring the actual movement data going into the class and trying to just make it work with magic numbers before I plug real data back into it.
Code:
public function MovingPlatform(x:Number, y:Number, w:Number, h:Number,
x2:Number, y2:Number, tw:uint, th:uint, looping:Boolean,
trigger:String, velocity:Number, endTriggers:String)
{
var s:Number = (FP.world as Box2DWorld).scale;
axis = new b2Vec2(x2, y2);
axis.Subtract(new b2Vec2(x, y));
axis.Multiply(1 / s);
this.velocity = velocity / s;
super(x, y, w, h, tw, th, b2Body.b2_dynamicBody); //The superconstructor creates the body (it's just a box) and places it in 'body'
var joint:b2PrismaticJointDef = new b2PrismaticJointDef;
joint.Initialize(body, _world.world.GetGroundBody(),
body.GetPosition(),
new b2Vec2( 1, 0));
joint.collideConnected = false;
joint.referenceAngle = 0;
joint.lowerTranslation = -5;
joint.upperTranslation = 5;
joint.enableLimit = true;
joint.maxMotorForce = 1;
joint.motorSpeed = 1;
joint.enableMotor = true;
var jnt:b2PrismaticJoint = _world.world.CreateJoint(joint)
as b2PrismaticJoint;
}
x2:Number, y2:Number, tw:uint, th:uint, looping:Boolean,
trigger:String, velocity:Number, endTriggers:String)
{
var s:Number = (FP.world as Box2DWorld).scale;
axis = new b2Vec2(x2, y2);
axis.Subtract(new b2Vec2(x, y));
axis.Multiply(1 / s);
this.velocity = velocity / s;
super(x, y, w, h, tw, th, b2Body.b2_dynamicBody); //The superconstructor creates the body (it's just a box) and places it in 'body'
var joint:b2PrismaticJointDef = new b2PrismaticJointDef;
joint.Initialize(body, _world.world.GetGroundBody(),
body.GetPosition(),
new b2Vec2( 1, 0));
joint.collideConnected = false;
joint.referenceAngle = 0;
joint.lowerTranslation = -5;
joint.upperTranslation = 5;
joint.enableLimit = true;
joint.maxMotorForce = 1;
joint.motorSpeed = 1;
joint.enableMotor = true;
var jnt:b2PrismaticJoint = _world.world.CreateJoint(joint)
as b2PrismaticJoint;
}
Any help on this would be brilliant.
Paul.