Projectiles and throwables

I am working on a multiplayer pvp game where players throw things at each other. I have kinematic characters but I was thinking spawning dynamic throwable objects would be easier since there would be all kinds of contacts and rebounding (off players, walls, platforms, other throwables etc)… but as I tried to add the “forces” on their init it seemed like nothing I did was able to give the throwable items enough velocity and the gravity was nearly impossible to get right too. I’ve worked with box2d dynamic objects in other engines/sdk’s and it wasn’t this hard.

Am I going about this wrong? If the players are kinematic, should everything be so? If so, are there any examples anywhere?

If dynamic is ok, are there any magic project gravity/scale/object settings you recommend as a starting point?

Thanks!

I just did an Angrybirds example where I used only dynamic collision objects. Applying a force to the dynamic object didn’t pose any problems (although I didn’t do it in init()). The force has to be quite significant though, perhaps you are using too small values?

I don’t really see a problem with the players being kinematic, unless you wish the projectiles to actually bounce off players when they hit?

@britzl I do hope to have the projectiles bounce off the players, so I think that dynamic would be better. I think I need to reset my numbers then and try again. I don’t know what to set the project gravity and scale at because I ended up with force values ranging from a few hundred to multiplied values in the millions and still wasn’t getting good results.

Also, I have a factory producing these projectiles and applying the force on init of the prototype object. Is there a better way to spawn it and send it moving?

Hey guys, update on what I have found.

I think I found some values that are working for my throwable and realistic gravity. However I’m running into some collision issues.

First my setup:

And here’s what I’m applying for force.

msg.post("#stone", "apply_force", { force = vmath.vector3(2500 * self.direction, 1500, 0), position = go.get_world_position() })

They have a good “feel” to the throw and I plan to implement aiming, but I’m a little baffled at some of the physics glitches I’m running into. The tile map collision with the stone is acting very random as it seems like the stone’s dynamic physics turn off or break through randomly. See Gif:

Any Ideas?? Thanks for looking!

The reason the gravity has to be so high is that we by default render in pixel space. The “normal” configuration for a physics world is to have a resemblance of 1 = 1 meter, so a character would be 1.5-2. In pixel space, characters are often 200 or more in size, so the gravity needs to be scaled accordingly to have a natural effect.

Judging by the size of the ball, the collision glitch looks like a case of bullet through paper. You can see more clearly what’s going on if you go through the trouble of starting your level (collection) through a collection proxy. Then you can use set_time_step to visually see where the ball is every frame. Hint: use discrete mode.

Edit: We also use Box2D when physics is set to “2D”, for “3D” it’s Bullet.

5 Likes

So, increasing the object’s size solved this issue for me currently. On to the next… :slight_smile:

I’ve got a new physics/logic question for you guys.

If I want these projectiles to be dynamic and bounce off characters etc… Then what would be the best way to “disable” them for “pickup”. For example… When a projectile comes to full rest, I want to disable it’s “collision object” so that the player can run over it and “pick it up”. At this point I’ll just remove the game object and add it back to the player’s inventory.

I guess my question is what events and contact data should I tie into to detect that the object is at rest/stopped moving/rolling??? Is this even the best way to go about this?

Main goal is to have some stones laying about the level, allowed to be picked up, but dynamic colliding objects only when they’re in motion.

Thanks!

Ok, so the object should be dynamic up until they are not moving anymore and at that time they should no longer interact with anything other than the player?

I’d try to have one dynamic collision object and one of type trigger (that is disabled from the start) and while the dynamic object is enabled you can in the update() function track either position or linear velocity. Once one of these values aren’t changing anymore you disable the dynamic collision object (by posting a disable message to it) and enable the trigger object.

Thanks for the tip! I’ll give that a shot and report back.