using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
//camera
public GameObject Eyes;
public float sensitivity = 4f;
//jump
public float VV;
public float jumpPower = 5f;
public float gravity = 9.81f;
//moving
public float speed = 5f;
public float rotSpeed = 10f;
public CharacterController cc;
// Use this for initialization
void Start () {
cc = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
//camera
float rotX = Input.GetAxis("Mouse X") * sensitivity;
float rotY = Input.GetAxis("Mouse Y") * sensitivity;
transform.Rotate(0, rotX, 0);
Eyes.transform.Rotate(-rotY, 0, 0);
//jump
if (cc.isGrounded)
{
VV = -gravity * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space))
{
VV = jumpPower;
}
}
else
{
VV -= gravity * Time.deltaTime;
}
Vector3 move = new Vector3(0, VV, 0);
cc.Move(move * Time.deltaTime);
//moving
float moveH = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
float moveV = Input.GetAxis("Vertical") * rotSpeed * Time.deltaTime;
transform.Translate(0, 0, moveV);
transform.Translate(moveH, 0, 0);
}
}