- Home /
How can i make my camera move in 3 dimensions?
I would like to know how to make my camera move and rotate in z,x and y axels so i can use it in a space game. The first person Controller and 3rd person controller only move in one level, because they are designed for a game with floors. Can some1 plz help me?
Answer by StephenLTGAMES · May 11, 2011 at 09:04 PM
transoform.rotate (may also work) of couse you would still need to program the buttons and appy a force to move foward .
you can add constant force to move in which ever direction you are currently in.
The above code can be used to change the values of x, y and the z axis (by applying different values to the axis you want to alter.
The cursor keys could be set up for up and down movement and turning to the left and to the right. (stafling or side movements for when fighting could be applied to the v and b buttons as its near the space bar which could be used for moving fowards or shooting.
To move forwards (the z axis is often used)
Go to unity script refrence
Look at rigid body.apply realative force. Transform.translate Rotate.
To have utter control over a space ship you need to think about what do i actually want it to do (do i want my camera to rotate downwards when the player presses the down key , do i want the camerea to roatate in the air while climbing.
When roatating to move left and right how would apply this motion when using 2 buttons. what button do i need to make it move fowards . Do i need it to be able to reverse.
Hope this helps
I like this approach, i was think that the camera could be focused on the mouse and shoot could be the clicking of the mouse, but just using the keyboard sounds intriguing. I'm going to have to play around with this :)
Its what i am doing for my current project but having problems with a load system at this stage anything would do. (i am however changing from first person to third person, allowing the player to land and also play in first or third person all time.)
Its okay i got it to work to a degree but for some reason it only saved when i exited my pause menu.
Answer by HHameline · May 11, 2011 at 08:00 PM
I think you want something like this:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public GameObject camera;
// Use this for initialization void Start () {
}
// Update is called once per frame void Update () { if (Input.GetKey("space")) { camera.transform.Translate(new Vector3(0, 10, 0)); } }
}
That will move the camera up in the y axis, when you press down the space bar.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Move object towards mouse in full 3D space 2 Answers
How i can make a first person controller that doesn't get affected by gravity? 2 Answers
Reference boolean check from other script (not working) 1 Answer
Moving the first person controller upwards and downwards 1 Answer