Advertisement
Guest User

Untitled

a guest
Dec 25th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.65 KB | None | 0 0
  1.         var physics = owner.get(PhysicsBody);
  2.         var world : World = physics.box2d.world;
  3.         var body = physics.body;
  4.         var ballPosition : Vec2 = body.getPosition();
  5.         var gravity : Float = -body.getGravityScale() * world.getGravity().y;
  6.         var maxHeight = targetPos.y - 2;
  7.        
  8.         var displacement : Vec2 = new Vec2(targetPos.x - ballPosition.x, targetPos.y - ballPosition.y);
  9.         var time : Float = Math.sqrt( -2 * maxHeight / gravity) + Math.sqrt(2 * (displacement.y - maxHeight) / gravity);
  10.         var velocityY : Float = Math.sqrt( -2 * gravity * maxHeight);
  11.         var velocityX : Float = displacement.x / time;
  12.         var initialVelocity : Vec2 = new Vec2(velocityX, -velocityY);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement