using UnityEngine; using System.Collections; public class thirdPersonController : MonoBehaviour { public string CAMERA_INPUT_X; public string CAMERA_INPUT_Y; public string MOVEMENT_INPUT_X; public string MOVEMENT_INPUT_Y; public string JUMP_INPUT; public Camera camera; public GameObject cameraCentre; public float cameraSpeedX = 250.0f; public float cameraSpeedY = 120.0f; public float cameraDistance = 10.0f; public float movementSpeed; public float jumpHeight; private float cameraX; private float cameraY; private float movementX; private float movementY; // Use this for initialization void Start () { cameraX = camera.transform.eulerAngles.x; cameraY = camera.transform.eulerAngles.y; } void FixedUpdate(){ movementX = Input.GetAxis (MOVEMENT_INPUT_X); movementY = Input.GetAxis (MOVEMENT_INPUT_Y); Vector3 velocity = new Vector3 (movementX, 0.0f, movementY)* movementSpeed * Time.deltaTime; //Debug.Log (velocity); velocity = Quaternion.Euler (0.0f,camera.transform.rotation.eulerAngles.y, 0.0f) * velocity; GetComponent().AddForce (velocity); //if (velocity != Vector3.zero) transform.rotation = Quaternion.Euler(new Vector3 (0.0f, camera.transform.rotation.eulerAngles.y, 0.0f)); if (Physics.Raycast (transform.position, -Vector3.up, 1.3f)) { //print ("Raycast succeeded"); if (Input.GetButtonDown (JUMP_INPUT)) { GetComponent().AddRelativeForce (0, jumpHeight, 0); } } } // Update is called once per frame void LateUpdate () { cameraX += Input.GetAxis(CAMERA_INPUT_X) * cameraSpeedX * 0.02f; cameraY += Input.GetAxis(CAMERA_INPUT_Y) * cameraSpeedY * 0.02f; Quaternion cameraRotation = Quaternion.Euler (cameraY, cameraX, 0.0f); Vector3 cameraPosition = cameraRotation * new Vector3(0.0f, 0.0f, -cameraDistance) + cameraCentre.transform.position; camera.transform.rotation = cameraRotation; camera.transform.position = cameraPosition; } }