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 );
The arrow is flying, but not realistic... I think that my miscalculations is not valid, please tell me in what could be the problem?