Hello to all,
i want to "attach" an entity to a other object (entity). Like a racket to a tennis player.
Only the arm will have collision to the ball object. The tennis player is just carrying the racket.
Q1) How do i create joint with box2d sugar - from one entity to another entity
Q2) How do i set the pivot of the racket to the edge (handle) and the other to the center of the tennis player.
Regards,
nightbyter
1 decade ago
by Joncom
<removed initial response>
Edit:
I think this guy maybe found a solution for that:
http://impactjs.com/forums/help/need-a-simple-example-of-a-multi-body-entity
Thank you Joncom,
i read this already. But it doesn't make a lot of sense to me, i could need an entry point help.
I am new to box2d and using your box2d sugar, because it is easier to get results.
Can i mix box2d sugar with "normal" box2d?
Is it possible to "link" to entities with your sugar as well?
nightbyter
1 decade ago
by Joncom
Quote from nightbyter
Can i mix box2d sugar with "normal" box2d?
Yes, everything that can be done with "normal" Box2D can be done also with the plugin. The plugin simply wraps common actions, such as setting position or velocity inside easy to use "shortcuts".
For example, setting position via
entity.pos.x = 30
actually forces this additional code to run:
entity.pos.x = 30;
var oldPos = entity.body.GetPosition();
var xScaled = entity.pos.x * Box2D.SCALE;
var newPos = new Box2D.Common.Math.b2Vec2(xScaled, oldPost.y);
entity.body.SetPosition(newPos);
Here's the (touched up) example from the other post:
// Spawn two entities
this.entity_a = ig.game.spawnEntity( EntityTest, 0, 0 );
this.entity_b = ig.game.spawnEntity( EntityTest, 0, 0 );
// Define how we're going to join two entities
var weldJointDef = new Box2D.Dynamics.Joints.b2WeldJointDef();
weldJointDef.bodyA = this.entity_a.body;
weldJointDef.bodyB = this.entity_b.body;
weldJointDef.collideConnected = false;
weldJointDef.localAnchorA = new Box2D.Common.Math.b2Vec2( 0, 0 );
weldJointDef.localAnchorB = new Box2D.Common.Math.b2Vec2( 0, 0 );
weldJointDef.referenceAngle = 0;
// Weld the entities together
ig.world.CreateJoint( weldJointDef );
Have you tried running it in your main.js
init
after loading the level?
You can learn about "b2WeldJointDef" and other Box2D stuff here:
http://www.box2dflash.org/docs/2.1a/reference/
Hey Joncom,
thank you very much. I will go for it today.
nightbyter
Page 1 of 1
« first
« previous
next ›
last »