Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var physics = owner.get(PhysicsBody);
- var world : World = physics.box2d.world;
- var body = physics.body;
- var ballPosition : Vec2 = body.getPosition();
- var gravity : Float = -body.getGravityScale() * world.getGravity().y;
- var maxHeight = targetPos.y - 2;
- var displacement : Vec2 = new Vec2(targetPos.x - ballPosition.x, targetPos.y - ballPosition.y);
- var time : Float = Math.sqrt( -2 * maxHeight / gravity) + Math.sqrt(2 * (displacement.y - maxHeight) / gravity);
- var velocityY : Float = Math.sqrt( -2 * gravity * maxHeight);
- var velocityX : Float = displacement.x / time;
- var initialVelocity : Vec2 = new Vec2(velocityX, -velocityY);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement