Flying arrows

General discussion about Box2D tutorials
Post Reply
Daboog
Posts: 22
Joined: Tue Jan 15, 2013 4:38 pm

Flying arrows

Post by Daboog »

Hello!
I wright from this example https://www.iforce2d.net/b2dtut/sticky-projectiles

Code: Select all

Vector2 flightDirection = arrowBody.getLinearVelocity();
float flightSpeed = flightDirection.nor().len(); //normalizes and returns length
           
Vector2 pointingDirection = arrowBody.getWorldVector( new Vector2( 1, 0 ) );
float dot = flightDirection.dot(pointingDirection);

float dragForceMagnitude = (1 - Math.abs(dot)) * flightSpeed * flightSpeed * dragConstant * arrowBody.getMass();
            
Vector2 force = new Vector2(-flightDirection.x * dragForceMagnitude,-flightDirection.y * dragForceMagnitude);
System.out.println("dot " + dot);
Vector2 arrowTailPosition = arrowBody.getWorldPoint( new Vector2( (float) -1.4, 0 ) );
arrowBody.applyForce( force, arrowTailPosition );
This is on Java.

The arrow is flying, but not realistic... I think that my miscalculations is not valid, please tell me in what could be the problem?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Flying arrows

Post by iforce2d »

I think before anyone will check your translation of C++ to Java, perhaps you could tell us what is not realistic about it, and whether you have changed anything from the C++ version.
Post Reply