So i am trying to make a camera follow a entity around, but also allow a player to to rotate the camera 360 degrees around the player model, and also control the height on the camera with a joystick. I have searched around the closest example I have to something similiar to this looked something like this
Code:
// A camera is hunting a target and turns with them, keeping the target always in the middle of the view.
var cam_dist[3] = -500,100,100; // xyz distance vector from camera towards the target
function chase_camera(target)
{
my = target; // The target Entity
// calculate the camera view's direction angle to the target
var cam_ang[3]; // direction angle of the camera to the target.
vec_diff(temp,nullvector,cam_dist);
vec_to_angle(cam_ang,temp);
cam_ang.roll = 0; // roll didn't change vec_to_angle
// permanent updating of the camera's position and angle
while (1)
{
// place the camera at the right position to the target
vec_set(camera.x,cam_dist);
vec_rotate(camera.x,my.pan);
vec_add(camera.x,my.x);
// Set the camera angles to the camera view direction
vec_set(camera.pan,cam_ang);
// and rotate it about the target angle
ang_add(camera.pan,my.pan);
wait(1);
}
}
While I understand some of this 'example' code, I do not see 'temp' defined anywhere, or a reason why it would be neccessary to define 'my' as the target? Albeit I am still learning the ins and outs of Lite-C I was under the assumption 'my' was always in reference to the the target entity.
Anyways if someone could give a better(clearer) example of how I would go about making a working camera chase, or explain this one to me I would greatly appreciate it.