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 matthew

I'm creating a basic demo based on the Box2D example and for some reason my entity will not move when I hit the mapped key. My code is virtually identical to the demo. The only thing that's really different is that mine is not animating (because there is no animation. I'll include the code, hopefully someone noticing something.

EntityKnocker = ig.Box2DEntity.extend({
	size: {x:48, y:24},
	//offset: {x: 4, y: 2},
	collides: ig.Entity.COLLIDES.NEVER,
	type: ig.Entity.TYPE.A,
	checkAgainst: ig.Entity.TYPE.NONE,

	animSheet: new ig.AnimationSheet('media/cloud.png',48,24),

	init: function(x, y, settings) {
		this.parent(x, y, settings);

		this.addAnim('idle', 1, [0]);
	},

	update: function() {
		if(ig.input.state('right')) {
			this.body.ApplyForce( new b2.Vec2(20,0), this.body.GetPosition() );
		}

		this.body.SetXForm(this.body.GetPosition(), 0);

		// Move it!
		this.parent();
	}
});

1 decade ago by dominic

Your code looks fine, I think. Did you maybe forget to bind a key to the 'right' action?

1 decade ago by matthew

Yes, I had. I fixed this by using ApplyImpulse instead of ApplyForce. Perhaps ApplyForce only applies when the entity is not in collision with something (in this case, the ground).

1 decade ago by Snowleopard

I was having this same issue too, with my entity not moving once I moved things over to box 2d. turns out the problem was that my entity was outside of the 'world', because my collision map didn't fully surround the entity. the solution was to move the world creation code outside of the layers loop within the loadLevel method of Box2DGame. just posting this incase someone else runs into the same problem, cause it was a pain to figure out.
Page 1 of 1
« first « previous next › last »