public void FixedUpdate() // Physics and movement { if (isLocalPlayer) { float t = HP / MaxHP; if (t == 0.0f) { t = 1.0f; } float k = Mathf.Lerp(SpeedMultiplyEnd, SpeedMultiplyStart, t); // Lower our health, more coffee we have, faster we are k *= (Energy > 0.0f) ? 4 : 1; // Quad speed under energetic if (!Dead) { // Fetch controls movementMagnitude = MovementTouch.GetMagnitude(); if (movementMagnitude > 0.0f) { movementDir = MovementTouch.GetDirection(); } movementAngle = Vector2.SignedAngle(new Vector2(movementDir.x, movementDir.y), Vector2.up); aimingMagnitude = ShootingTouch.GetMagnitude(); aimingDir = ShootingTouch.GetDirection(); aimingAngle = Vector2.SignedAngle(new Vector2(aimingDir.x, aimingDir.y), Vector2.up); // Simple movement Controller.SimpleMove(CharacterSpeed * (new Vector3(movementDir.x, 0, movementDir.y)) * movementMagnitude * k); // Anamation control bool animator_running = Animator.GetBool("running"); bool animator_shooting = Animator.GetBool("shooting"); Animator.SetFloat("speed", k); if (movementMagnitude > 0 && !animator_running) { Animator.SetBool("running", true); } else if (animator_running && movementMagnitude == 0) { Animator.SetBool("running", false); } if (!animator_shooting) { if (aimingMagnitude >= 0.8) // Manually aim { CmdShoot(new Vector3(aimingDir.x, 0, aimingDir.y)); Animator.SetBool("shooting", true); } else if (ShootingTouch.GetReleased() && ShootingTouch.GetCaptured()) // Auto aim nearest player { var colliders = Physics.OverlapSphere(transform.position, 8, LayerMask.GetMask("Character")); var nearest = float.MaxValue; aimingDir = movementDir; foreach (var c in colliders) // Scan for game objects of player character { var go = c.gameObject; if (go == gameObject) { continue; // Not me! } var dist = (go.transform.position - transform.position).magnitude; if (nearest > dist) { var character = go.GetComponent <PlayerController>(); if (character.GetVisible()) { nearest = dist; aimingDir = (go.transform.position - transform.position).normalized; aimingDir = new Vector3(aimingDir.x, aimingDir.z, 0); aimingAngle = Vector2.SignedAngle(new Vector2(aimingDir.x, aimingDir.y), Vector2.up); VisibleBody.transform.rotation = Quaternion.AngleAxis(aimingAngle, Vector3.up); } } } CmdShoot(new Vector3(aimingDir.x, 0, aimingDir.y)); Animator.SetBool("shooting", true); } } if (aimingMagnitude == 0.0 && movementMagnitude > 0.0) { VisibleBody.transform.rotation = Quaternion.AngleAxis(movementAngle, Vector3.up); // If we move, face towards movement } else if (aimingMagnitude > 0.3) { VisibleBody.transform.rotation = Quaternion.AngleAxis(aimingAngle, Vector3.up); // If we shoot, face towards aim } } else if (Animator.GetBool("died") && !respawning) { respawning = true; StartCoroutine(WaitForRespawn()); } } if (isServer) { if (Energy > 0.0f) { Energy -= Time.deltaTime; if (Energy < 0.0f) { Energy = 0.0f; } } if (Invuln > 0.0f) { Invuln -= Time.deltaTime; if (Invuln < 0.0f) { Invuln = 0.0f; } } if (Quad > 0.0f) { Quad -= Time.deltaTime; if (Quad < 0.0f) { Quad = 0.0f; } } } }