Topview camera

Hi,

A camera like this is called a topview camera or flyby right?



One that gets input with WASD. with a aspecific angle from the top. Is there a tutorial about this, how to make one?

Ive read about making an invisible box in the air and attaching the camera to that or something.

Thanks

Use this :

[java]

private Node player ;

private Vector3f cameraPosition = new Vector3f(0,cameraOffset,0);

private Vector3f cameraInitialUp ;



@Override

public void simpleInitApp()

{

cameraInitialUp = cam.getUp().clone();

}



@Override

public void simpleUpdate(float tpf)

{

cam.setLocation(player.localToWorld(cameraPosition,null));

if (cameraType == CameraType.TOP_DOWN_CAMERA)

{

cam.lookAt(player.getWorldTranslation(), cameraInitialUp);

}

}

[/java]

Hello!



The simple way would be to use a chasecam camera controller attached to the vehicle or character that the player is controlling. You can restrict the rotation of the chasecam however you like, and even set the angle and distance at which it follows the object if you wish. It’s pretty snazzy. The controls for the vehicle/character would be up to you to implement (turn and move style, point and click, or direct movement etc etc), and the camera would handle the view all on its own.



Cheers!

~FlaH

Hi,



yes the idea of tehflah is quite nice. But instead of following a selected unit you should put an invisible sphere on the terrain that the camera will chase. This sphere must be in a special CollisionGroup so that it can only collide with the ground. By pressing WASD you do not move the camera but instead you move this invisible sphere over the ground. The benefit is that the camera will move very nicely over your terrain and will increase and decrease its height automatically when you scroll over bumpy terrain.

Dodikles thisis exactly what I mean, I dont want to chase something but just a camera in air.

So basically when you control the camera (=sphere with WASD). But I dont know how to do this… I thought of an invisible cube?

With a fixed distance.

But this would bring a problem… because if I have a sphere which moves on the ground, that means the camera gets stuck if the sphere collides with a rock or something.

Hello again!



Ah I see, more of an RTS style camera.



In this case, your concern about the invisible sphere getting stuck is actually moot. As Dodikles said: “This sphere must be in a special CollisionGroup so that it can only collide with the ground.” In other words, what you’re saying shouldn’t ever happen. As long as your map doesn’t have some severe cliffs or something you should be fine. If you DO have severe cliffs, then you’d just want the sphere to be able to climb anything. No biggy. ~ Imagine an invisible sphere that only knows how to move on the X and Z axis on it’s own and it takes on whatever Y the terrain gives it. That’s essentially what you’d want in that case.



Cheers!

~FlaH

There is also a ChaseCamera already implemented in JME3, just look into the Docs for it. I believe that every modern game that uses such a perspective (C&C,War/Starcraft, Total War) uses this technique. Good luck :slight_smile:

That camera angle looks like its about 45 degrees turned in both y and x direction.

You really dont need a chasecam unless you want that smooth motion.

But otherwise to get the angle do:

[java]cam.setLocation(0,0,0);

cam.lookAt(new Vector3f(-1,-1,0),Vector3f.UNIT_Y);[/java]



After that you can set whatever location you want on the camera and it will still look the same direction.

But since you just want that movment of the cam do:

[java]

InputListerner il = new InputListerner();

inputManager.addMapping("P", new KeyTrigger(KeyInput.KEY_P));

inputManager.addListener(il, "P");

[/java]

The input listener should look something like this:

[java]public class InputListerner implements ActionListener {

public void onAction(String binding, boolean value, float tpf) {

if (binding.equals("P")) {

cam.setLocation(cam.getLocation().add(Vector3f.UNIT_X));

}

}

}

[/java]



Then you can add more keys but this is the concept for getting input.

Hope this helps :smiley:

@Dodikles well I have never seen a chasecam in C&C, But I don’t know, It looks like in C&C the user can control the cam himself wihout the cam drags itsself with a vehicle (like chasing).



@addez thanks :slight_smile: Helped a lot

But this line

cam.setLocation(0,0,0);

Says that It cannot be applied to three integers, even if I import the Vector3f





The maker of Imperi also did it the right way somehow, The cam “flies” over the maze.

ahh sorry.

It should be cam.setLocation(new Vector3f(0,0,0));



If you want it to fly over then how about creating a flyVector?

flyVector = new Vector3f(0,0,0);



in each update you do:

cam.setLocation(cam.getLocation().add(flyVector));



and so instead of setting the location when pressing P you do:

[java]public class InputListerner implements ActionListener {

public void onAction(String binding, boolean value, float tpf) {

if (value){

if (binding.equals("P")) {

flyVector = flyVector.add(Vector3f.UNIT_X);

}

}

} else {

if (binding.equals("P")) {

flyVector = flyVector.add(-Vector3f.UNIT_X);

}

}

}

[/java]



So now, as long as you hold it in, the flyVector will be 1,0,0.

When you release the button, it will do:

[java] flyVector = flyVector.add(-Vector3f.UNIT_X);[/java]

It will substract 1 in x so the result is 0,0,0 thus the cam stop moving :slight_smile:



If you want height adjustments too you gonna need ray casting…