SHARE
TWEET
Untitled
a guest
Nov 20th, 2016
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- Vector2 differencePos = new Vector2(pos.x - nextPosition.x, pos.y - nextPosition.y); //used to find desired angle
- float trajectory = (float) Math.atan2(differencePos.y, differencePos.x); //desired angle, in radians
- this.rads = enemyBody.getTransform().getRotation();
- float difference = (this.rads-trajectory);
- System.out.println(trajectory);
- int sign = (int) Math.signum(difference);
- //System.out.println(sign);
- if(sign<0)
- this.rads += 2*pi/180;
- else this.rads -= 2*pi/180;
- this.dir = new Vector2((float) Math.cos(rads), (float) Math.sin(rads));
- enemyBody.setTransform(this.pos, rads);
- 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.

