Box2D questions

Hi everyone,

I have some questions regarding box2d.

First of all I’m trying to develop a simple game with the use of box2d. The principle of the game is that the user will have a gun (Triangle) which will be placed at the bottom of the screen and asteroids (Box) will fall from the top of the screen, users mission is to shoot the asteroids with the help of the gun.
The game interaction will be simple. When the user touches the screen, he will be able to control the gun’s shooting direction but with the same touch the gun will also start to shoot. So with one touch he can shoot and control the direction. When the bullet hits the asteroid (Box) the asteroid (Box) will disappear from the screen.

The game now is at the stage where the user can shoot bullets with the gun but there are some issues that I haven’t overcame like: I can’t control totally the bullets with the mouse…It’s limited. I’ve also managed to destroy the asteroids when the bullets hits them. My only problem now is how to control the gun(triangle) so it can move with the same direction as the bullets and also make the bullets to be more “neatly” I’ve attached the patch so you can see what I mean. The gun’s(triangle) density is set to 1 so it’s static…but If I change the value to 0 it will have the gravity of the world and it will not stay at the position I want to.

Any help would be great.

Box2d (350.7 kB)

Hi vasilis , I was hooked about the project and made ​​a possible solution. see if it works for you and what you wanted.

gameNave.v4p (89.1 kB)

@obernardoo wow…I didn’t expect someone will do a proper example to solve my problems…Thanks…In a way this is what I was looking for…I will give it a try to see if I can make it work properly with the patch I’m doing and I will let you know how it’s going…Thanks again.

@obernardoo It’s working…Basically my problem was how to move the gun and in your case it was working pretty good…It’s strange though because in my patch the “ApplyImpulse” node is red but it’s still working so no worries(I think)…Thanks again!!

@bernardo you solved my problem too … thanks…

The ApplyImpulse is red because it is enabled with a NIL value going in to it.

You should only enable the ApplyImpulse when there is a value present, if you don’t vvvv could crash. This plugin seems fairly stable, but other plugins will cause you big problems if you have a NIL have present when the plugin is a expecting a number/string.

Easy way to get around the red node here is to use a Count (value) that counts the input values, attach the Count output pin to the ApplyImpulse. The ApplyImpulse will only be enabled when count is > 0.

Great!! Thanks Garreth