Positioning the camera in overhead view

Hi all,

In my game design I use first person view for movement and then switch to an overhead view for combat. This is working fine.

When I setup combat I select a player and the scene is re-rendered with the camera raised few meters and facing down.

Then I want to select a specific player on the screen at a coordinate a move the camera so it’s directly overhead. This part for me is not working.

So in my keyBehavior class I get the Transform3D from the player object and from that get his vector. Then I try to place the camera at that vector. But the camera view goes haywire.

Code is like this:

// Local new transform3D so it should be empty
Transform3D t = new Transform3D();

// init the Transform3D from the selected object
selectedPlayer.getTG().getTransform(t);

// Get the vector for this object
Vector3d vector = new Vector3d();
t.get(vector);

// Reset the KeyBehavior Transform3D
t3d = new Transform3D();

// Set the KeyBehavior TransformGroup
targetTG.getTransform(t3d);

// This is an instance var for repeated calcs
toMove.setTranslation(theMove);

// move the camera? ???
t3d.mul(toMove);
targetTG.setTransform(t3d);


TIA

Hi,

You can use the helper method  void lookAt(Point3d eye, Point3d center, Vector3d up) in the Transform3D class.

Transform3D trns = new Transform3D();
Point3D center = "position of player"
Point3D eye = "position of player + x distance over his head"  

Vector3D up ="forward direction of the player"  //assuming Z axis as Up in the game world , this vector must be in X/Y plane

trns.lookAt(eye, center, up);

targetTG.setTransform(trns);