Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Datamosh

Hello!
What's the simplest way to change the pivot (at any time) of a polygon shape attached to a body?

Thanks!

1 decade ago by Joncom

What is this "pivot" you're trying to change? Do you mean the "origin" of a body?

If you rotate a body, it rotates around its origin. You could also say it "pivots" around the origin. Is that what you mean, or something else?

If you do mean origin, I'm not sure you can change it. I believe it's always at the center of the body.

What are you trying to do and why?

1 decade ago by Datamosh

Hi Joncom, thank you very much for responding.

Exactly. I meant the origin of the body.
If this change is not common, maybe it's not what I'm looking for.
In my game, when the player gets into a vehicle, I want to stay in the driver's seat, but when I rotate the vehicle and player, it rotates incorrectly. I thought that changing the origin to the center of the car this would be solved.
As additional information, the player can leave anytime the vehicle.

/>			</div>
		</div>
			<div class=

1 decade ago by Joncom

Could explain your image and what it's demonstrating a little more please? What is wrong with the way the car rotates? How would you like it to happen instead?

1 decade ago by Datamosh

The player wrongly rotates into the car, not kept in the driver's seat.
If the player is in the center of the car works well, but is not what I want.

I think an animation is better to understand the problem.
/>			</div>
		</div>
			<div class=

1 decade ago by Joncom

Maybe try welding the player to the car so he doesn't move?

// 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 );
Page 1 of 1
« first « previous next › last »