Quaternion to Vector3

Ok so I’m sending a raycast a my camera to see if anything
is in the way and if so move the camera to that point.
But I can’t seem to get this to work because unity
wants a Vector3 not a Quaternion. So does anybody know how to fix this.

var targetCamera : Transform;
var maxDistance = 0.0;

function Start(){
maxDistance = targetCamera.GetComponent(SmoothFollow).distance;
}

function Update(){
var rotation = Quaternion.LookRotation (targetCamera.position - transform.position);
var hit : RaycastHit;
if (Physics.Raycast (transform.position, rotation, hit, maxDistance)) {
targetCamera.GetComponent(SmoothFollow).distance = hit.distance;
}
else
targetCamera.GetComponent(SmoothFollow).distance = maxDistance;

}

I would actually do something like this myself:

//Attach this script to the Main Camera

//The target below has an array "[]" attached so there can be multiples of the same name
var target : GameObject[];

//This is the same target as the target above
//But now we are further defining it
//Find is used to find target's game object name
var target : GameObject[].Find(replaceThisWithTheObjectName);

function Update () {
	var hit : RaycastHit;
	
	//Now we cast our Raycast function
	if (Physics.Raycast(transform.position, transform.forward, hit)) {
		//If the raycast records a RaycastHit with a target then the camera will look at it
		if (hit.collider.target) {
			transform.LookAt(target.position)*Time.smoothDeltaTime;
		}
	}
}

!!EDIT!!:

Instead of sending a raycast at your camera you should be sending a raycast from your camera to see if anything is in the way.

If you want to make the camera go to that object then replace my last “if” with:

if (hit.collider.target) {
     transform.position(target.position)*Time.smoothDeltaTime;
}

Well that was not quite what I was looking for but it pointed me in the right direction,
my script works now so I never have to look at a wall in the way of my person again :lol: well hopefully.

You can use hit.position to get the vector3 position of the raycast hit. Could then set the camera.transform to the hit.position.