racing camera problems, ?mabey floating point error?

Started by
4 comments, last by cdrw 19 years, 8 months ago
i have a camera that will circle around the player and get behind it, but when i make a 180 it sputters alittle around a its position behind the car, like its a floating point accumulation error? it wont stay in one spot, it jars around the spot its supposed to go behind the car off of a 180 degree turn, is it floating point error? what can i do about this? ;;;;edit 10 munites later;;;;;;;;; ok im pretty sure its just my fault, i think i sometimes overshoot my desired camera position vector when moving the camera around, anybody care too see my code? ;;;;another edit;;;;;;;;;;;; i think it is me oversooting my desired mark, when ever the camera catches fully up with the spot its supposed to be at, it jitters around the spot some o please some one help me with my third person camera delima, or imna have to make a 3d isometric game, which sounds fun anyways, oh my god ill make anything other then a fps [Edited by - cdrw on August 3, 2004 9:31:42 PM]
"am i supposed to be able to do sh_t with this?" oink snort
Advertisement
I assume you've got some kind of check like this:

  cameraangle  = GetCameraCurrentAngle(camera);  if (cameraangle < desiredangle)  {    cameraangle = cameraangle + 5;  }  else  if (cameraangle > desiredangle)  {    cameraangle = cameraangle - 5;  }  SetCameraCurrentAngle(camera, cameraangle)


The problem with this kind of check is that you will constantly overshoot your desired angle. A better implementation would be something like this:

  cameraangle  = GetCameraCurrentAngle(camera);  if (cameraangle < (desiredangle - 5))  {    cameraangle = cameraangle + 5;  }  else  if (cameraangle > (desiredangle + 5))  {    cameraangle = cameraangle - 5;  }  else  {    cameraangle = desiredangle;  }  SetCameraCurrentAngle(camera, cameraangle)


The above concept will apply to vectors too, but you see what I mean :)

Of course, it would be nice to see your source code too :)

Hope this helped,
FReY
do unto others... and then run like hell.
I simply make it like this:

diff = actualAngle - wantedAngle;

actualAngle += diff/10.0f;

This makes the camera move quickly at first, then slowly get to it's exact position. You can play with the /10.0f to make it move more quickly or slowly. The further away from the desired angle you are, the faster it will first move :).
Okay, in that case I recommend that you do a check to make sure your difference is enough. ie.

#define EPSILON      (0.015625f)diff = (actualAngle - wantedAngle) / 10.0f;if (fabs(diff) < EPSILON){  actualAngle = wantedangle;}else{  actualAngle += diff;}


edit:
Also, are your wantedangle and actualangle in the same revolution? ie. if wantedangle = 763 and actualangle = 3, you don't want to go through 2 revolutions to make your actual angle the same as your wantedangle. If I were you, I would fit your wantedangle within 180 degrees of your actualangle (by either adding or subtracting multiples of 360 degrees from it - or 2PI if you're using radians)

Hope that helped :)
do unto others... and then run like hell.
I think I do the camera work alot less complicated then you are.
I dont think I ever find a "camera angle".
I just use the lookat function on every frame step.

here's my comented code though,
pos is the craft's(car's) current position,
and velocity is its velocity vector
campos and camdir are global variables,
so they retain their values out of the turn of the framestep
(you knew that)
and camdir and campos are vectors
	void positionCamera(Vector3 pos, Vector3 velocity)	{		velocity = -velocity;//reverse the velocity vector		velocity.normalise();//normalise the reverse velocity direction		velocity *= 300;	//multiply it by the distance you with the camera to follow by		Vector3 position = pos + velocity;//add the multiplied above to the position of the craft and this is now the target place for the camera		if(accelerate == true)		//if the up(acceleration) button is being pressed down		{		campos = Vector3(position.x,(position.y+100),position.z);//get a cam position here while accelerating		camdir =  campos - mCamera->getPosition();// get the camera direction here		camdir.normalise();							//normalise the camera direction		mCamera->move(camdir*(mMoveScale*speed));		//move the camera by the direction, but dont worry about stopping		mCamera->lookAt(mShipNode->getPosition());	//look at the craft		follow = true;								//set to camera move by the camdir after accelerating		}		else if (follow == true)					//if to follow after accelerating		{		mCamera->move(camdir*(mMoveScale*speed));				mCamera->lookAt(mShipNode->getPosition());		Vector3 soaphairgellstop = campos - mCamera->getPosition();////here you stop following if the......		if(fabs(Magnitude(soaphairgellstop)) < 1)////....soaphargellstop(heh) is less then 5,which you might want.....		{follow = false;}						 ////....increase if the speed grows		}	}


[Edited by - cdrw on August 4, 2004 3:08:55 PM]
"am i supposed to be able to do sh_t with this?" oink snort
bla bla bla

just bringing my post back into first page view
"am i supposed to be able to do sh_t with this?" oink snort

This topic is closed to new replies.

Advertisement