void Update() { //Check if frozen for movment and other abilities to be active if (!freeze) { //Do the Calculations for rotation rotation.x += Input.GetAxis("Mouse X") * sensitivity.x; rotation.y += Input.GetAxis("Mouse Y") * sensitivity.y; rotation.y = Mathf.Clamp(rotation.y, rotationMin.y, rotationMax.y); transform.localEulerAngles = new Vector3(0.0f, rotation.x, 0.0f); camera.transform.localEulerAngles = new Vector3(-rotation.y, 0.0f, 0.0f); //Movement Controls if (!hitSomethingInAir) { Vector3 targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical")); targetVelocity = transform.TransformDirection(targetVelocity); targetVelocity = new Vector3(targetVelocity.x * speed, rigidbody.velocity.y, targetVelocity.z * speed); Vector3 velocityChange = targetVelocity - rigidbody.velocity; rigidbody.AddForce(velocityChange, ForceMode.VelocityChange); } if (Input.GetButtonDown("Crouch")) { transform.localScale -= new Vector3(0.0f, 0.25f, 0.0f); } if (Input.GetButtonUp("Crouch")) { transform.localScale += new Vector3(0.0f, 0.25f, 0.0f); } if (Input.GetButtonDown("Sprint")) { this.speed = 10f; } if (Input.GetButtonUp("Sprint")) { this.speed = 5f; } if (onGround && Input.GetButtonDown("Jump")) { rigidbody.AddForce(transform.up * jumpVelocity, ForceMode.VelocityChange); } //Item handel this stuff m8 if (Input.GetButtonDown("Interact")) { RaycastHit hit; Ray ray = gameObject.GetComponentInChildren <Camera> ().ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2)); if (Physics.Raycast(ray, out hit)) { if (hit.transform.gameObject.tag == "Interactable") { Inventory.Add(hit.collider.gameObject); InventoryGUI.Add(hit.collider.gameObject); hit.collider.transform.position = InventoryBag.transform.position; hit.collider.transform.rotation = InventoryBag.transform.rotation; hit.collider.transform.parent = InventoryBag.transform; } } } //Weapon Interactions if (Input.GetButtonDown("Fire2")) { //Knock dem bitches back RaycastHit hit; Ray ray = camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0.0f)); if (Physics.Raycast(ray, out hit, knockbackDistance)) { if (hit.collider.tag == "Gnome") { Gnome gnome = hit.collider.gameObject.GetComponent <Gnome> (); gnome.knockbackGnome(transform); } } } if (Input.GetButtonDown("Fire1")) { RaycastHit hit; //ray through the middle of the screen, i.e. where the player is looking Ray ray = gameObject.GetComponentInChildren <Camera> ().ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2)); if (Physics.Raycast(ray, out hit)) { if (hit.collider.tag == "Gnome") { Gnome gnome = hit.collider.gameObject.GetComponent <Gnome> (); //TODO: weapons should be the things dealing damage. once the equip system is set up, change this to be something like `currentWeapon.DealDamage(gnome);` DealDamage(gnome); } } } } }