Page 1 of 1

Flying arrows

Posted: Tue Mar 26, 2013 9:33 am
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?

Re: Flying arrows

Posted: Tue Mar 26, 2013 3:02 pm
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.