Super Smash Bros Camera
This is just a simple modification of the already existing chase camera app state, but I thought I would post it, because it contains code from the actual chase cam that allows for the “smooth movement”.
As the title suggests, it acts like the camera from the game Super Smash Bros, if you’ve ever played that.
Please Note: This is functional but not fully optimised, so it will be somewhat ineffecient until improved
How it works:
The app state creates a new
target, which has it’s position set to the same as the spatial/node in your scene that you want the camera to follow. Using linear interpolation, the
target node accelerates towards the spatial/node that it’s tracking, bringing the camera with it.
Since the camera is a child to the target node, it always follows it and preserves the same local translation that is initially set. Simply put: the camera doesn’t actually move (or tilt), the only thing that changes in the update loop is the position of
Super Smash Bros essentially operates on 2D axis, within a 3D world, which means that the camera rotation is always locked to face the same direction. You do not need to ever set the camera rotation, in fact you cannot as it will be overwritten since in the update loop the camera always faces the target node.
It has exactly the same methods as the chase camera app state, with four additions taken from the
ChaseCamera class in JME:
First you must declare the new object:
private SmashCameraAppState smashCameraAppState;
You can do this within
Initialize() from any app state, so long as you have access to the state manager.
smashCameraAppState = new SmashCameraAppState(); getStateManager().attach(smashCameraAppState); //the players mean is just an example of what you could use, it would have it's location //set to the mean location of everything that you want to track on each update smashCameraAppState.setTarget(playersMean); smashCameraAppState.setSmoothMotion(true); smashCameraAppState.setChasingSensitivity(3f);
After you create your camera object, you will want to set it’s local position relative to the
target node. This will be preserved, unless you decide to change it:
//change these values as desired cam.setLocation(Vetor3f.ZERO);//this indicates no local translation from the target node
Here is the code you need to get it working.
I can barely take credit for this, as 90% was written by @nehon, but I hope some of you find this useful.
Right now, it is super basic, but I am planning on expanding and polishing this in the near future.