Box2D arrow flight and attaching to targets tutorial

iforce2d · 4K views · 2011 · 1:26

Open on YouTube

Game programming & enginesIndie game developmentdemo

Why Stack Overflow recommends it

Stack Overflow users link it when answering Box2D and libGDX questions about throwing projectiles, since it shows the arrow-flight and sticking behaviour working in a physics engine.

Recommended by 2 people across 2 different months, 2012 to 2018.

What it is

A 1.5 minute screen capture by iforce2d showing the demo scene for the 'sticky projectiles' Box2D tutorial, where arrows fly through the air and stick into targets. It accompanies a written tutorial on the iforce2d site and shows the finished result rather than explaining the code.

What people said

Recommends mk_ · 2017-03 · Stack Overflow · on “How to achieve the following effect with libGDX?”

You need to add some physics to your app (ex. Box2d). Then you 'throw' canon ball with some velocity and some direction/angle. Physics engine do rest for you. Here you have tutorial for box2d: [this video] Very very basic example for throw something without box2d. For your example you need to calculate right 'power' for target position. public class SampleApp extends ApplicationAdapter { Sprite sprite; Vector2 velocity = new Vector2(0, 0); Vector2 terminateVelocity = new Vector2(2000, 2000); Vector2 friction = new Vector2(200, 300); Vector2 position = new Vector2(0, 0); Vector2 launchPower = new Vector2(0, 0); boolean shotNow; @Override public void render() { update(Gdx.graphics.getDeltaTime());

Recommends Louis Langholtz · 2018-01 · Stack Overflow · on “physics of javelin throwing in box2d”

There's an online tutorial by iforce2d that explains how to do what you're asking [LINK] . I recommend checking out. There's also a video demonstration [this video] of what the results look like that I've also found useful and recommend checking out.

Cites iforce2d · 2012-05 · Stack Overflow · on “How do I prevent jitter between moving kinematic platform and a dynamic body in Box2D?”

Are you talking about a visibly noticeable jitter, or just that you get a lot of BeginContact/EndContact callbacks? If the latter, there may be nothing you can do about that. If you need to know when the ball is on the platform, you might have to put another slightly larger fixture onto the ball body as a sensor to detect when it's on the platform. If you are talking about a visibly noticeable jitter I would be a little surprised. I have done basically the same thing but found no jitter (see ball on top of platform in far right: [this video] )