chase camera help

Posted By: boyax

chase camera help - 06/08/09 08:24

Hi,
What I'm trying to do is adjust camera's position so that:
1. When the spaceship's velocity is constant, the camera tends to occupy certain spot behind the ship; the distance between that spot and the spaceship is constant and does not depend on spaceship's velocity.
2. When the spaceship is accelerating, the camera starts to lag behind
3. When the spaceship is slowing down, the camera closes on the spaceship

Any idea? and How i can make the camera adjustment smooth..?
Hope someone could help.
Thanks
Posted By: KiwiBoy

Re: chase camera help - 06/08/09 08:36

Normal sin/cos will keep the constant distance Im thinking then modify according to taste.
distance = camera.x, spaceship.x; sort of thing to describe its 'constant'
If(vec_dist(my.x, spaceship.x) > camera_dist.x)
{
or if(spaceship_move > distance) etc...find a way to express accelleration and decelleration...

then modify for the speed differences maybe?
its probably the approach I would take and maybe will soon for follower NPC's.
Posted By: Germanunkol

Re: chase camera help - 06/08/09 11:38

Code:
var camDist = 100;
var camMaxDist = 200;
var camMinDist = 60;
var camAngle = 15;
		VECTOR camGoal;
	var camSpeed = .7;
	var oldCamPos[3];
	
	while(1)
	{
		
		camDist = clamp(camDist + mickey.z*time_step/5,camMinDist,camMaxDist);
		vec_set(camGoal,vector(-camDist*cos(camAngle),0,camDist*sin(camAngle)));

		vec_rotate(camGoal,vector(ship.pan,ship.tilt,ship.roll)); 
		vec_add(camGoal,ship.x);
		
		vec_diff(temp,camGoal,camera.x);vec_scale(temp,time_step*camSpeed);
		vec_add(camera.x,temp);
		
		vec_set(camera.pan,ship.pan);
		
		wait(1);
	}

check out this code, it should do exactly what you wanted it to.

-No need for trig (it tends to mess up in 3d space games anyways)
-easy implementation of shaking cameras
-mouse wheel changes distance to ship
-hope it helps.
Posted By: boyax

Re: chase camera help - 06/09/09 04:14

Thanks Germanunkol. It's useful, I'll try this.

By the way, is it ok if you could illustrate the below code for me. smile
Code:
vec_set(camGoal,vector(-camDist*cos(camAngle),0,camDist*sin(camAngle)));		vec_rotate(camGoal,vector(player.pan,player.tilt,player.roll));
vec_add(camGoal,player.x);
	
vec_diff(temp,camGoal,camera.x);
vec_scale(temp,time_step*camSpeed);
vec_add(camera.x,temp);
		
vec_set(camera.pan,player.pan);


I'm just looking at the manual.. but, still didn't know the theory behind it what you do.

Thanks
© 2023 lite-C Forums