Moving the Camera around my Player

Hey guys,

i am trying to build up a game where i am moving a sphere as my Player with the Arrow-Keys.

Everything works fine!

My Problem is that i want to build a labyrinth, in which the player sees the Playersphere from behind and a little bit up. When the Player is changing directions with the Arrow-Keys the Camera should move around the object, so that the player ist always looking into the direction he is moving.
Just like in Need for Speed or other similar Games, when u turn around the camera turns around, too.

Is there a posibility to do so? A tutorial or anything that can help me would be awesome.

Greets
treceguete

I am sorry for my bad english, unfortunatelly its not my mothertongue…

Just make your camera a child of the sphere. (in the hierarchy drag your main camera onto the sphere) It then becomes a child of the sphere.

Set the cameras co-ordinates (X Y Z) to 0, 0, 0 (that’s dead centre of the sphere)

Now move your camera back and up a little to a position where the view is good for you.

Now the good bit… wherever you move your sphere the camera will follow, whenever you turn/rotate your sphere the camera will turn with it.

:slight_smile:

Parent/child positioning/movement tutorial

http://unity3d.com/learn/tutorials/modules/beginner/editor/the-hierarchy-and-parent-child-relationships

This is a very basic script for a simple camera follow control.

#pragma strict

var target : Transform;

var distance : float;


function Update()
{     
	transform.position.z = target.position.z -distance;
  	transform.position.y = target.position.y+25;
 	transform.position.x = target.position.x;
}

Target is the transform/object that you want the camera to follow. (in your case the sphere) Put this script onto your main camera and play around with the positioning until you get the desired result.

:slight_smile: