Getting an error trying to reposition a camera, plz help

So basically I have two cameras in the scene, one third person camera(tpcam) and one first person camera(fpcam).

The default view is FPS, I want when you hit V for the tpcam to snap to the location/rotation of the fpcam. Then smoothly move back to it’s original position/rotation.

So as to simulate a smooth transition from fpcam to tpcam.

I’m using two cameras because the equipped weapon is parented to the fpcam.

This script is on the tpcam, the code that actually toggles the cameras is elsewhere on the fpcam. Which is just a simple boolean

	if (Input.GetButtonDown ("View"))
	{
		fpsCam = !fpsCam;
	}

======>Only Problem I’m having here is with the smoothdamp code, I can’t figure out how to pass vector3 positions into it, as I think it only takes floats<======

Here’s my error message that occurs on line of the mathf.smoothdamp;
– Assets/-Scripts/tpCAimAssist.js(40,44): BCE0023: No appropriate version of ‘UnityEngine.Mathf.SmoothDamp’ for the argument list ‘(UnityEngine.Vector3, UnityEngine.Vector3, float, float)’ was found. –

Here’s the code;

public var fpCamera : Camera;						//Used for Switching between 1st/3rd person view
public var tpCamera : Camera;

public var camTransVel : float = 1.0;				//Smooth Velocity
public var smoothTime : float = 1.0;

private var fpCamPos : Vector3;						//Camera positions
private var tpCamPos : Vector3;
private var tpCamRot : Quaternion;

function Update()
{
//If Button is pressed switch between 1st/3rd person view
	if (head.GetComponent("CameraLook").fpsCam == false) 
	{
	//Store current tpCamPossition
		fpCamPos = fpCamera.transform.position;
		tpCamPos = tpCamera.transform.position;
		tpCamRot = tpCamera.transform.rotation;
	//Snap tpsCam to fpsCam pos and rot
		tpCamera.transform.position = fpCamera.transform.position;
		tpCamera.transform.rotation = fpCamera.transform.rotation;
	//Smoothly move tpCam back to its pos
	var newPosition = Mathf.SmoothDamp (fpCamPos, tpCamPos,camTransVel, smoothTime);
	tpsCamPos = tpCamera.transform.position = newPosition;
	
	//Turn tpCam on and fpCam off
		fpCamera.camera.enabled = false;
		tpCamera.camera.enabled = true;
	}
}

If you have any input at all on this it’s much apreciated, I’ve been stumped for hours now.

Mathf.SmoothDamp expects two floats for current and target not vector3.
Using two cameras can lead into a lot of troubles (synching skyboxes,fog settings, culling mask etc) . I prefer using only one camera with two different states and positions (fps/3rd person). When in fps mode the camera is positioned at the fps target point and when in 3rd person mode the camera is moved along it’s negative forward vector multiplied by the current distance.
To switch from one mode to the other just lerp the distance value.
Another advantage is that you can automatically animate the camera between both position when there’s an object blocking the view in the 3rd person mode.

Hmm thank you, your reply just saved me a lot of trouble in the future. Would you mind sharing your code of how you go about doing this?

I originally decided against using one camera as the weapon was parented to the camera, but I spose I can come up with an easy enough work around to that.

Thanks again for your reply I appreciate it :]

Hi,
all the codes that I have are pretty special to one game and wont help you that much. But if you want I will help you. The camera script for a 3rd person view extremely depends on how you build your player/camera hierarchy. I prefer to have a camera that is not a child of the player. The player code should be done in Update() and FixedUpdate() and the camera will positioned and rotated in LateUpdate() to ensure that the camera target is correctly positioned. Another topic is whether the camera target is inside the player mesh or not. If its inside you have to enable/disable the mesh render when switching between both positions. If you want to shot in the 3rd person view should be above the players head to avoid that the player block the view.

Hmm well right now I’m using a prop character, that’s basically a capsule with a sphere on top.

The sphere, serving as a prop head, has the mouselook script attached, with a crosshair offset as a child. So when you move the mouse it moves only this head and crosshair, and not the camera at all.

The fps camera itself is in the same location as the sphere and has a smoothFollow script attached with the crosshair as the target. And the gun/equipped weapon is a child of the camera, that also has a smoothFollow script attached with the target as the crosshair.

The capsule under the head has a Walker script attached to it, that leads all the wasd movement. Both the fps camera and head prop have a short script attached to copy the transform of the Walker object. And the Walker object has a short script to copy the rotation of the head object.

The result is fairly nice, I’ve averaged the frames for smoother mouse movement too.

Right now I have the 3rd person cam set up as a child of the fps cam, offset behind the prop character for an over the shoulder effect, so it pivots around the head of the character. This also has a smoothFollow script attached, which at first had odd results but I have it working quite well now.

I’ve a feeling my setup here is a bit too complex, and I’ll certainly be removing the second camera.

I spose, on the fps camera, in it’s script that copies the transform of the Walker object, I could lerp an offset with a GetButtonDown function to move the camera into position.

The sort of third person cam I’m aiming for is an over the shoulder Gears Of War type view, with an option to hold a key down and zoom in right up to the shoulder looking down the weapon, I’ve achieved most of this just by changing the field of view.

Anyway, thanks for your advice you’ve been very helpful, any more advice you have at all would be much appreciated! :]

I think your setup is too complex and has to many scripts. The smoothFollow script is nice but only works if you have a lot space around the player and will bring a lot of trouble in indoor scenes.

Use an animated skinned mesh to test your scripts because the capsule and the sphere always look the same but your character may not.

If your fps camera works fine than the main difference for the 3rd person camera is the position:
cam.transform.position = target.transform.position - (cam.transform.forward*distance).

Yeah I had a feel it was too complex. So do you have any tips for reducing the complexity?

And I might be asking a lot here but could you give me a quick run through of how you’d go about setting up the control system with a rigged/skinned model?

I’m a 3d artist so it won’t be a problem for me to get a nice model.

Thanks again for your advice! :]

For the start I would use an existing character from one of the unity demos. Start with the FirstPersonController prefab and try to integrate both cameras. Then assign the skinned mesh and sync the animation according to input.

That’s a great idea to use one of the models form the demo’s I already have em here, never occurred to me. Thanks again for your advice you’ve been very helpful! :]