SHARE
TWEET

Untitled

a guest Nov 20th, 2016 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                 Vector2 differencePos = new Vector2(pos.x - nextPosition.x, pos.y - nextPosition.y); //used to find desired angle
  2.                 float trajectory = (float) Math.atan2(differencePos.y, differencePos.x); //desired angle, in radians
  3.                
  4.                 this.rads = enemyBody.getTransform().getRotation();
  5.                
  6.                    
  7.                     float difference = (this.rads-trajectory);
  8.                     System.out.println(trajectory);
  9.                     int sign = (int) Math.signum(difference);
  10.                     //System.out.println(sign);
  11.                     if(sign<0)
  12.                     this.rads += 2*pi/180;
  13.                     else this.rads -= 2*pi/180;
  14.                
  15.                 this.dir = new Vector2((float) Math.cos(rads), (float) Math.sin(rads));
  16.                 enemyBody.setTransform(this.pos, rads);
  17.                 enemyBody.setLinearVelocity(this.dir.x * speed, this.dir.y * speed);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top