Hey guys, kind of embarrassed this is going to be my first post as its all questions 🙂 but I appreciate any help ahead of time as I'm running out of time.
I'm creating a light gun, basically like a flashlight with box2d collision. I currently have a triangle connected to a mouse joint that follows the mouse constantly; however, it rotates sort of randomly because the joints are both in the middle of the triangle, is there a way to stop rotation or at least prevent this from happening. I believe fixed rotation is the command?
On top of this my lightGun needs to only rotate in front of the player, so it must follow the mouseJoint on a limited angle. Is it possible to limit the rotation of a mouse joint?
here is my current code.
I apologize for "the_circle" I swapped from a circle to a triangle recently.
Also alpha code 😉
thanks to ANYONE who can help, thanks,
Mike
I'm creating a light gun, basically like a flashlight with box2d collision. I currently have a triangle connected to a mouse joint that follows the mouse constantly; however, it rotates sort of randomly because the joints are both in the middle of the triangle, is there a way to stop rotation or at least prevent this from happening. I believe fixed rotation is the command?
On top of this my lightGun needs to only rotate in front of the player, so it must follow the mouseJoint on a limited angle. Is it possible to limit the rotation of a mouse joint?
here is my current code.
I apologize for "the_circle" I swapped from a circle to a triangle recently.
Also alpha code 😉
Code:
var bd:b2BodyDef;
var the_circle:b2PolygonDef = new b2PolygonDef();
var the_joint:b2DistanceJointDef = new b2DistanceJointDef();
//Triangle Code required for implementation
the_circle.vertexCount = 3;
the_circle.vertices[0].Set(0, -2);
the_circle.vertices[1].Set(2, 2);
the_circle.vertices[2].Set(-2, 2);
the_circle.density = 0.01;
the_circle.friction = 0.4;
the_circle.restitution = 0.3;
bd = new b2BodyDef();
the_circle.isSensor = true;
bd.position.Set(halfWidth +4, halfHeight * 20);
use fixedRotation = true;
var circle:b2Body = world.boxWorld.CreateBody(bd);
var gun:CitrusShape = new CitrusShape(circle.CreateShape(the_circle), ShapeNames.LIGHT_GUN);
circle.SetMassFromShapes();
the_joint.Initialize(circle, topBodyShape.body, gun.body.GetPosition(), topBodyShape.body.GetPosition());
the_joint.collideConnected = true;
var joint:b2DistanceJoint = world.boxWorld.CreateJoint(the_joint)as b2DistanceJoint;
var body = circle;
var mouseJointDef:b2MouseJointDef = new b2MouseJointDef;
mouseJointDef.body1 = world.boxWorld.GetGroundBody();
mouseJointDef.body2 = body;
mouseJointDef.target.Set(circle.GetPosition().x, circle.GetPosition().y);
mouseJointDef.maxForce = 75;
mouseJointDef.timeStep = m_timeStep;
mouseJoint=world.boxWorld.CreateJoint(mouseJointDef) as b2MouseJoint;
_lightCircle = gun;
var the_circle:b2PolygonDef = new b2PolygonDef();
var the_joint:b2DistanceJointDef = new b2DistanceJointDef();
//Triangle Code required for implementation
the_circle.vertexCount = 3;
the_circle.vertices[0].Set(0, -2);
the_circle.vertices[1].Set(2, 2);
the_circle.vertices[2].Set(-2, 2);
the_circle.density = 0.01;
the_circle.friction = 0.4;
the_circle.restitution = 0.3;
bd = new b2BodyDef();
the_circle.isSensor = true;
bd.position.Set(halfWidth +4, halfHeight * 20);
use fixedRotation = true;
var circle:b2Body = world.boxWorld.CreateBody(bd);
var gun:CitrusShape = new CitrusShape(circle.CreateShape(the_circle), ShapeNames.LIGHT_GUN);
circle.SetMassFromShapes();
the_joint.Initialize(circle, topBodyShape.body, gun.body.GetPosition(), topBodyShape.body.GetPosition());
the_joint.collideConnected = true;
var joint:b2DistanceJoint = world.boxWorld.CreateJoint(the_joint)as b2DistanceJoint;
var body = circle;
var mouseJointDef:b2MouseJointDef = new b2MouseJointDef;
mouseJointDef.body1 = world.boxWorld.GetGroundBody();
mouseJointDef.body2 = body;
mouseJointDef.target.Set(circle.GetPosition().x, circle.GetPosition().y);
mouseJointDef.maxForce = 75;
mouseJointDef.timeStep = m_timeStep;
mouseJoint=world.boxWorld.CreateJoint(mouseJointDef) as b2MouseJoint;
_lightCircle = gun;
thanks to ANYONE who can help, thanks,
Mike