I want to move the tank, but I dont want to do tremble the camera, if the tank climb a small hill, I want the camera still static.
I mean, the camera is attach to the cannon tank, ok, but I dont want that the camera follow each movement of the tank, only follow the tank and I use their rotation Up, Down, and 360 degrees (X,Y Axis) whith the Script MouseLook.
There is a form to do? Or I need to be more explicit?
yup, what you want to do is known as a “chase cam”, a camera that follows the object of interest but is somewhat laggy in catching up to its moves.
What this generally means is that on every update the camera should move proportionally from where it is now to where it would have been if always firmly “locked” onto the tank.
For position, during your fixed update try something like this:
First, define a camera location you want when the tank is at rest, eg:
Vector3 camera_location = new Vector3(0,5,-10);
(this is 5 units above and 10 units behind the tank)
There’s a script in this thread that implements a physics-controlled camera that might be of use to you. It doesn’t rigidly follow the object, but gets “pulled” along by it gently and it has steadicam-type behaviour as regards tracking the ground.
// Smooth towards the height of the target
var target : Transform;
var smoothTime = 0.3;
private var yVelocity = 0.0;
function Update ()
{
var newPosition = Mathf.SmoothDamp(transform.position.y, target.position.y,
yVelocity, smoothTime);
transform.position.y = newPosition;
}
But when I compile appear a Error:
“Cannot modify the return value of `UnityEngine.Transform.position’ because it is not a variable”
and… what is wrong? I do it like the Unity Script Page do.
yeah, you’ve run into the #1 sucky thing about scripting in C#, that transform.position is a property or whatever and its elements aren’t directly modifiable.
You have to reassign the entire variable like so transform.position = new Vector3(blah blah blah);
nb; when you get an error the first thing you should do is search google for the error text. You never know what you’ll find, eg: