/// <summary> Gets input from mouse and controller to get offset vector. </summary> /// <returns> The offset vector. </returns> private Vector2 GetOffset() { Vector2 mouse = new Vector2((Managers.GameState.Instance.Inverted ? 1 : -1) * CustomInput.MouseYRaw, CustomInput.MouseXRaw); Vector2 controller = new Vector2( (Managers.GameState.Instance.Inverted ? 1 : -1) * (CustomInput.Bool(CustomInput.UserInput.LookUp) ? CustomInput.Raw(CustomInput.UserInput.LookUp) : CustomInput.Raw(CustomInput.UserInput.LookDown)), CustomInput.Bool(CustomInput.UserInput.LookRight) ? CustomInput.Raw(CustomInput.UserInput.LookRight) : CustomInput.Raw(CustomInput.UserInput.LookLeft)); return((mouse + controller) * Managers.GameState.Instance.Sensitivity); }
private Vector2 GetAimDir() { float up, right; if (CustomInput.UsingPad) { up = CustomInput.Bool(CustomInput.UserInput.LookUp) ? CustomInput.Raw(CustomInput.UserInput.LookUp) : CustomInput.Raw(CustomInput.UserInput.LookDown); right = CustomInput.Bool(CustomInput.UserInput.LookRight) ? CustomInput.Raw(CustomInput.UserInput.LookRight) : CustomInput.Raw(CustomInput.UserInput.LookLeft); } else { Vector3 norm = (this.mousePos - this.sceneCamera.WorldToScreenPoint(this.transform.position)).normalized; up = norm.y; right = norm.x; } return(new Vector2(right, up)); }
private bool ShouldAim() { if (CustomInput.UsingPad) { float up = CustomInput.Bool(CustomInput.UserInput.LookUp) ? CustomInput.Raw(CustomInput.UserInput.LookUp) : CustomInput.Raw(CustomInput.UserInput.LookDown); float right = CustomInput.Bool(CustomInput.UserInput.LookRight) ? CustomInput.Raw(CustomInput.UserInput.LookRight) : CustomInput.Raw(CustomInput.UserInput.LookLeft); return(up != 0 || right != 0); } else { if (this.mousePos != new Vector3(CustomInput.MouseX, CustomInput.MouseY, 0)) { this.mousePos = new Vector3(CustomInput.MouseX, CustomInput.MouseY, 0); return(true); } return(false); } }
void Update() { if (CustomInput.Bool(CustomInput.UserInput.Accept, playerNum)) { transform.position = new Vector3(transform.position.x, CustomInput.Raw(CustomInput.UserInput.Accept, playerNum), transform.position.z); } else { transform.position = new Vector3(transform.position.x, 0, transform.position.z); } if (Input.GetKeyUp(KeyCode.P)) { currentInput++; if (currentInput >= inputs.Length) { currentInput = 0; } Debug.Log(inputs[currentInput]); CustomInput.setGamePadButton(CustomInput.UserInput.Accept, inputs[currentInput], playerNum); } }
/// <summary> Aims the gun. </summary> private void Aim() { float up, right; if (CustomInput.UsingPad) { up = CustomInput.Bool(CustomInput.UserInput.LookUp) ? CustomInput.Raw(CustomInput.UserInput.LookUp) : CustomInput.Raw(CustomInput.UserInput.LookDown); right = CustomInput.Bool(CustomInput.UserInput.LookRight) ? CustomInput.Raw(CustomInput.UserInput.LookRight) : CustomInput.Raw(CustomInput.UserInput.LookLeft); } else { Vector3 norm = (new Vector3(CustomInput.MouseX, CustomInput.MouseY, 0) - camera.WorldToScreenPoint(transform.position)).normalized; up = norm.y; right = norm.x; } if (right < 0) { FaceLeft(); } else { FaceRight(); } if (up == 0 && right == 0) { } else if (up == 0) { if (right < 0) { gun.transform.rotation = Quaternion.Euler(0, 0, 0); } else { gun.transform.rotation = Quaternion.Euler(0, 0, 0); } } else if (right == 0) { if (up < 0) { gun.transform.rotation = Quaternion.Euler(0, 0, 270); } else { gun.transform.rotation = Quaternion.Euler(0, 0, 90); } } else { if (right < 0) { gun.transform.rotation = Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan(up / right)); } else { gun.transform.rotation = Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan(up / right)); } } }
//fixed update runs on a timed cycle (for physics stuff) void FixedUpdate() { if (Util.GameState.state != Util.GameState.State.Playing) { return; } if (!ragdollIsActive) { rgbdy.AddForce(2 * Physics.gravity * rgbdy.mass); if (currState == Enums.PlayerState.Moving || currState == Enums.PlayerState.InAir || currState == Enums.PlayerState.Jump) { //the following logic will accuratly rotate the player to the direction they want to go float up = CustomInput.Bool(CustomInput.UserInput.Up) ? CustomInput.Raw(CustomInput.UserInput.Up) : CustomInput.Raw(CustomInput.UserInput.Down); float right = CustomInput.Bool(CustomInput.UserInput.Right) ? CustomInput.Raw(CustomInput.UserInput.Right) : CustomInput.Raw(CustomInput.UserInput.Left); magnitude = new Vector2(up, right).magnitude; if (magnitude > 1) { magnitude = 1; } if (up == 0 && right == 0) { } else if (up == 0) { if (CustomInput.Bool(CustomInput.UserInput.Left)) { transform.rotation = Quaternion.Euler(0, 270 - cameraTracking.Theta, 0); } else { transform.rotation = Quaternion.Euler(0, 90 - cameraTracking.Theta, 0); } } else if (right == 0) { if (CustomInput.Bool(CustomInput.UserInput.Down)) { transform.rotation = Quaternion.Euler(0, 180 - cameraTracking.Theta, 0); } else { transform.rotation = Quaternion.Euler(0, 0 - cameraTracking.Theta, 0); } } else { if (CustomInput.Bool(CustomInput.UserInput.Down)) { transform.rotation = Quaternion.Euler(0, 180 + Mathf.Rad2Deg * Mathf.Atan(right / up) - cameraTracking.Theta, 0); } else { transform.rotation = Quaternion.Euler(0, Mathf.Rad2Deg * Mathf.Atan(right / up) - cameraTracking.Theta, 0); } } if (currState == Enums.PlayerState.Moving) { if (sluggish) { rgbdy.AddForce(-this.transform.right * 0.6f * moveForce * magnitude); if (rgbdy.velocity.x > 0.6f * maxSpeed) { rgbdy.velocity = new Vector3(0.6f * maxSpeed, rgbdy.velocity.y, rgbdy.velocity.z); } if (rgbdy.velocity.z > 0.6f * maxSpeed) { rgbdy.velocity = new Vector3(rgbdy.velocity.x, rgbdy.velocity.y, 0.6f * maxSpeed); } } else { rgbdy.AddForce(-this.transform.right * moveForce * magnitude); if (rgbdy.velocity.x > maxSpeed) { rgbdy.velocity = new Vector3(maxSpeed, rgbdy.velocity.y, rgbdy.velocity.z); } if (rgbdy.velocity.z > maxSpeed) { rgbdy.velocity = new Vector3(rgbdy.velocity.x, rgbdy.velocity.y, maxSpeed); } } } if ((currState == Enums.PlayerState.InAir || currState == Enums.PlayerState.Jump) && move) { rgbdy.AddForce(-this.transform.right * moveForce * airControl * magnitude, ForceMode.Acceleration); if (rgbdy.velocity.x > maxSpeed) { rgbdy.velocity = new Vector3(maxSpeed, rgbdy.velocity.y, rgbdy.velocity.z); } } } //if (!inAir) // rgbdy.velocity = new Vector3(rgbdy.velocity.x, 0, rgbdy.velocity.z); if (jump) { rgbdy.AddForce(this.transform.up * jumpForce, ForceMode.Impulse); jump = false; } if (knockBack) { rgbdy.AddForce(this.transform.right * maxKnockbackSpeed, ForceMode.Impulse); knockBack = false; } } }
void Update() { if (Util.GameState.state == Util.GameState.State.Playing && !disable) { if (paused) { paused = false; anim.speed = animSpeed; rgbdy.useGravity = true; rgbdy.velocity = vel; } if (Input.GetKeyUp(KeyCode.U)) { die(); } #region StatusEffects if (sluggish) { anim.speed = 0.6f; } else { anim.speed = 1; } #endregion anim.SetFloat("speed", magnitude); if (health <= 0 || this.transform.position.y < -20) { //Create a ragdoll until we respawn if (respawnTimer > 0) { if (!ragdollIsActive) { die(); //this.GetComponent<Rigidbody>().useGravity = false; } //this.gameObject.transform.position = new Vector3(tempRag.HipN.position.x+1,tempRag.HipN.position.y, tempRag.HipN.position.z + 1); respawnTimer -= Time.deltaTime; } else { Respawn(); FindObjectOfType <GameState>().playerDeaths++; FindObjectOfType <GameState>().lives--; //this.GetComponent<Rigidbody>().useGravity = true; } } move = false; if (CustomInput.Bool(CustomInput.UserInput.Up) || CustomInput.Bool(CustomInput.UserInput.Down) || CustomInput.Bool(CustomInput.UserInput.Left) || CustomInput.Bool(CustomInput.UserInput.Right)) { move = true; } TouchingSomething(); //get next state currState = machine.update(inAir, move, hit, animDone); if (invunTimer > 0) { hit = false; invunTimer -= Time.deltaTime; invun = true; } else { invun = false; } if (dead) { dead = false; } //run state doState[(int)currState](); if (health <= 0) { die(); } if (doAttack) { doAttack = false; attackInstance = Instantiate(attack); attackInstance.transform.position = attackPos.position; } //state clean up if (prevState != currState) { doOnce = false; animDone = false; jump = false; hit = false; anim.SetInteger("state", (int)currState); if (attackInstance != null) { Destroy(attackInstance.gameObject); } } prevState = currState; } else { if (!paused) { animSpeed = anim.speed; anim.speed = 0; rgbdy.useGravity = false; vel = rgbdy.velocity; rgbdy.velocity = new Vector3(); paused = true; } } }