I am doing a maze game. I prepared maze and character. I want to control character bird’s eye view camera.(like pacman) Can you help me how can i do it? I worked to change script codes first person and 3rd person controller but i can not do it.
clunk47
2
The SIMPLEST way to do this is to move the camera to the height you want, make it look at your character, then just make the character the PARENT of the camera by dragging the camera onto the character in Hierarchy view. Let me know if you want something more complex.
Thank you for help. But how i will control character? Am i not need a script?. I worked the change 3rd Person Controller. I modelled char in blender and import unity. I must control it direction keys.
If you are making a game very similar to Pac-Man then I assume that you are working something very similar to a 2D game.
- Make the camera as “Orthogonal”
- Add a script which has reference the Transform the player & a float variable which stores the required height for the camera to be from the player
- Then your script would somewhat look like this.
SAMPLE CODE
public class CameraMovement : MonoBehaviour
{
Transform Player;
float Height;
Quaternion DefaultCameraAngle;
void Start ()
{
// Initializing variables
Height = 10f;
DefaultCameraAngle = Quaternion.Euler(90,0,0);
Player = GameObject.Find("Player").GetComponent<Transform>();
// Initializing camera
this.transform.position = Player.transform.position;
this.transform.rotation = DefaultCameraAngle;
}
void Update ()
{
this.transform.position = new Vector3(Player.transform.position.x, (Player.transform.position.x + Height), Player.transform.position.z);
}
}
-
You have place the above script on the Camera to work and name the target player as “Player”.
-
Else the cheapest way would be to child the Camera to the Parent (the Player) and set the camera setting throught the inspector,
considering that the maze extends beyond the camera’s frustum.
var speed = 3.0;
var rotateSpeed = 3.0;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis (“Horizontal”) * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis (“Vertical”);
controller.SimpleMove(forward * curSpeed);
}
@script RequireComponent(CharacterController)
I used this script for control my character like pacman. but character turn round itself when push “w” and “s”. Also “a” and “s” button do not active. What is the problem?