#### Minigame

• int
• Posts: 55
« on: February 13, 2013, 06:28:04 am »
I have a click to walk system in my game app, and previously used a method that just followed the player from behind, but now am trying to base things around a user controlled POV that uses arrow key input (360 degree left / right rotation, and 45 degrees from the ground, or 15 degrees above ground level).
The user controlled camera works fine, but I can't get it to follow the player. I know about Camera.CAMERA_MOVE*, but it goes off screen from being called each tick. Is there a function to determine the distance from the player object, so that I could force a MOVEIN / MOVEOUT appropriately maybe?

#### EgonOlsen

• Posts: 11899
« Reply #1 on: February 13, 2013, 07:11:25 am »
I'm not 100% sure which kind of camera you have in mind here, but you have the position of the camera and you have the position of the player. With that, it's simple to calculate the distance between the two. For example by using http://www.jpct.net/doc/com/threed/jpct/SimpleVector.html#distance(com.threed.jpct.SimpleVector)

#### Minigame

• int
• Posts: 55
« Reply #2 on: February 13, 2013, 08:44:32 pm »
Camera issues have been resolved, and another issue has occurred that I've toyed with for hours and cannot solve on my own.
The problem is trying to snap the player in a specific direction.. but I'm unable to determine a proper rotation value.

Directions are stored in an enum:
Code: [Select]
` NORTH(0, (float) Math.PI * 2), NORTHEAST(1, ((float) Math.PI * 7) / 4), ... etc`
and here's what is being done to "try" to determine the next rotation direction, and definitely where the problem is coming from:
Code: [Select]
` private void turnTo(Mob mob, SimpleVector dest) { // TODO calculate correct angle between location and destination float angle = mob.getTransformedCenter().calcAngle(dest); // problem here ?? System.out.println("angle="+angle); // Find closest direction Direction dir = Direction.getClosestDirectionForAngle(angle); mob.updateDirection(dir);`