as you can see, my character is controlled by torques. Therefore, I can’t parent my camera to him , because the camera would be spinning! So I’m trying to make a 3d camera follow script but I’m having no luck. Most people say to use transform.position = parent.transform.position + new Vector3(something,something,something) but if there was,for instance, a U-turn in one of the levels, the camera would be facing backwards and the player wouldn’t be able to see where he is going! So how can I make my camera-follow script so that the camera would always be looking at my character but following him at the same time? Thanks!
I had the same problem, this script uses vector, but you could give it a try…
Create a JavaScript and insert this code:
#pragma strict
var myPos : Vector3;
var myPlay : Transform;
function Update()
{
transform.position = myPlay.position + myPos;
}
Then insert the Script in your camera and in the “My Play” insert your character (ball).
You might need to change the position of the camera in the script to have a better view. Hope it helps!
IF it doesn’t work, try this one:
#pragma strict
var myPos : Vector3;
var myPlay : Transform;
public var target: Transform;
function Start()
{
transform.LookAt(target);
}
function Update()
{
transform.position = myPlay.position + myPos;
}
This version of the Script will make the camera also look at the player. I tested it and it is working fine even when you need to make 90° curves and all.
I have another method; Create a Cube GameObject, put a script on it to get player’s position minus the values of x, y & z you want (how far you want your cube to be from the player or certain object), and then script the Camera to get exactly the Cube’s position, and then LookAt() the player or object you want your camera to face.
In less words, the Cube is basically a lure, and it has a distance from the player, then the Camera gets the cube position and looks towards the player.