using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour {
public float movementSpeed;
public float rotationSpeed;
public float rotX;
public float rotY;
public float rotZ;
public Rigidbody rb;
public bool playerIsOnTheGround = true;
// Use this for initialization
private void Start() {
rb = GetComponent<Rigidbody>();
}
//Update is called once per frame
void FixedUpdate() {
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey("w")) {
transform.position += transform.TransformDirection(Vector3.forward) * Time.deltaTime * movementSpeed * 2.5f;
} else if (Input.GetKey("w") && !Input.GetKey(KeyCode.LeftShift)) {
transform.position += transform.TransformDirection(Vector3.forward) * Time.deltaTime * movementSpeed;
} else if (Input.GetKey("s")) {
transform.position -= transform.TransformDirection(Vector3.forward) * Time.deltaTime * movementSpeed;
}
if (Input.GetKey("a") && !Input.GetKey("d")) {
transform.position += transform.TransformDirection(Vector3.left) * Time.deltaTime * movementSpeed;
} else if (Input.GetKey("d") && !Input.GetKey("a")) {
transform.position -= transform.TransformDirection(Vector3.left) * Time.deltaTime * movementSpeed;
}
}
void Update() {
if (Input.GetButtonDown("Jump") && playerIsOnTheGround)
{
rb.AddForce(new Vector3(0, 5, 0), ForceMode.Impulse);
playerIsOnTheGround = false;
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.name == "Floor")
{
playerIsOnTheGround = true;
}
}
rotX -= Input.GetAxis ("Mouse Y") * Time.deltaTime * rotationSpeed;
rotY += Input.GetAxis ("Mouse X") * Time.deltaTime * rotationSpeed;
if (rotX < -90) {
rotX = -90;
} else if (rotX > 90) {
rotX = 90;
}
transform.rotation = Quaternion.Euler (0, rotY, 0);
GameObject.FindWithTag ("MainCamera").transform.rotation = Quaternion.Euler (rotX, rotY, 0);
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}