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 pm99

Hey guys,
Just wanted to use the box2d physics that is baked into the jetpack template but into the jump and run template (which does not have box2d enabled by default).

Can I just:
1. add the require for the box2d plugin.
2. Add the actual plugin to the plugin folder.
3. extend my game, entities etc. using ig.Box2dGame.extend and ig.Box2DEntity.extend
4. then go and create those entities that will behave with physics

...anything else missing or am i being naive again, thinking it's that easy?

I like the jetpack template but don't really want my game to have a jetpack. Just simple jump n run for now.

Sincerely,
PM99

1 decade ago by Arantor

Well, change the animation and it won't be a jetpack. You will, however, have to look at the style of coding used in the jetpack scenario - whereas normally you'd just play around with accel.y and vel.y, you have to explicitly this.body.ApplyForce() to make the jump work since that's how Box2D works.

1 decade ago by pm99

@Arantor,
Thanks for the reply. I'm sorry, I see now that I did not clarify enough haha....
yes, what I meant was to not have the jetpack functionality altogether, and instead just use the simple 'jump' in the 'jump n run' template. Just changing the animation is not what i was after.

So in player.js, of the jetpack template, 'jetpack' section, here's the jetpack code...

		// jetpack
		if( ig.input.state('jump') ) {
			this.body.ApplyForce( new b2.Vec2(0,-30), this.body.GetPosition() );
			this.currentAnim = this.anims.jump;
		}
		else {
			this.currentAnim = this.anims.idle;
		}

... and in player.js of the jump n run, 'jump' section it's ...

		// jump
		if( this.standing && ig.input.pressed('jump') ) {
			this.vel.y = -this.jump;
		}
		

So Arantor, if you're saying that I can play around with the 'applyForce and the accel.y and vel.y' functions of the jetpack template that I may be able to get it to look like a 'jump', I will certainly try that.

However, just swapping these two out does not change the characters behaviour (the game never loads... sorry I forgot to get the debug output - I'lll add it once i get back). I believe there may be more to it, as mentioned above in my three points.

1 decade ago by Arantor

You should not be manipulating accel.y and vel.y directly at all, because you'll get things out of sync with how Box2D sees the world.

When you press jump, set a flag that indicates that you're jumping, when the player collides with something vertically, reset the flag, then simply check for ig.input.state('jump') && this.jumping or whatever the flag's called.

1 decade ago by pm99

hmm.. okay.

I suspect in my humble opinion, this direction is over my noob head.

Arantor, let me ask you this, if you please...

why is it not that I cannot make a require of plugin.dbox2d.entity for all my entities
and require 'plugins.dbox2d.dbox2d' in main.js,
and declare MyGame and EntityPlayer = ig.Box2dGame.extend

would the above not 'enable' box2d physics in the 'jump n run' game?

Sorry for persisting with this question, but i'm a coding noob (like I took Pascal and Basic in grade 9 in 1984!... talk about revealing my age) so if I can stay on the path of least coding (baby steps) the better I am for it (vs. getting dejected for my inadequacies and turning to drinking... again).

PM99

1 decade ago by Arantor

Firstly, no, it's not as simple as that. Box2D doesn't just drop in, it completely replaces an entity and game structure. Entities normally have acceleration in absolute axes (x and y) and velocity in the same, but Box2D doesn't work like that, it works much more in a physics-based rather than a game-based manner.

Box2DEntities don't use accel or vel normally (I'm not even sure off hand if they use them at all), and the main method of causing movement is to issue the ApplyForce method to that object, since that not only updates the acceleration and so on but makes sure that Box2D actually updates everything.

Just as Impact normally uses accel and vel, Box2D uses its forces - and the two are different in so many ways that they don't overlap.

1 decade ago by pm99

Thanks Arantor.
Page 1 of 1
« first « previous next › last »