Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Camera Question.

Started by X5-Programmer Nov 15, 2004 at 4:04 PM 0 replies 250+ views
Original Post
X5-Programmer
X5-Programmer
Hi, I have working with camera for my game and try to lock it to the char and rotate it around him when he moves. Let me show what I have done so far. I have this Vectors. Vector3 mPos; Vector3 mView; Vector3 mUp; Vector3 mPlayer; the Rotate function is done like this.

void CCamera::Rotate_Position(float speed)
{	
	Vector3 vVector = mPos - mView;

	mRotate.z = (float)(mView.z + sin(speed)*vVector.x + cos(speed)*vVector.z);
	mRotate.x = (float)(mView.x + cos(speed)*vVector.x - sin(speed)*vVector.z);
}

and Move fuction.

void CCamera::Move_Camera(float speed)
{
	Vector3 vVector = mView - mPos;
	
	mPos.x  = mPos.x  + vVector.x * speed;
	mPos.z  = mPos.z  + vVector.z * speed;
	mView.x = mView.x + vVector.x * speed;
	mView.z = mView.z + vVector.z * speed;
}

How can I lock the camera this to the character using this functions? and also rotate around him when I move the character forwards. I have try do like this. A set camera function.

void CCamera::SetCamera(float xPos, float zPos)
{
	mView.x += xPos-mPos.x;
	mView.z += zPos-mPos.z;
	mPos.x = xPos;
	mPos.z = zPos;
}

to Set the camera to a point, then I do like this. SetCamera(player.x, player.z); player.x += 0.005f * m_timer.elapsed; player.z += 0.005f * m_timer.elapsed; Rotate_Position(0.05f * m_timer.elapsed); Now it rotates around the camera point not the players point. Im going crasy soon, maybe I need more math to do this.
-[ thx ]-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.