www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Minigame on February 13, 2013, 06:28:04 am

Post by: Minigame 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?
Post by: EgonOlsen 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) (http://www.jpct.net/doc/com/threed/jpct/SimpleVector.html#distance(com.threed.jpct.SimpleVector))
` NORTH(0, (float) Math.PI * 2), NORTHEAST(1, ((float) Math.PI * 7) / 4), ... etc`
` 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);`