// Update is called once per frame void Update() { if (isDead || isLocked) return; animator.SetBool("LyingDown", isLyingDown); animator.SetBool("IsUp", isUp); aimLine.enabled = isUp; if (isLyingDown) { Collider[] hits = Physics.OverlapSphere(transform.position, 4); foreach (Collider c in hits) { Painting paint = c.GetComponent<Painting>(); if (paint != null) { drainGroup = paint.splatGroup; } } if (drainGroup != null) { player.Drain(0.025f * Time.deltaTime); drainGroup.Drain(1f * Time.deltaTime); isReviving = true; } if (isReviving && drainGroup == null) { isLyingDown = false; } } else { if (animator.GetCurrentAnimatorStateInfo(3).IsName("Disabled")) { isUp = true; animator.SetBool("IsUp", isUp); } } if (!isUp) return; padState = GamepadInput.GamePad.GetState(GamepadInput.GamePad.Index.One); leftStickInUse = (padState.LeftStickAxis.magnitude > leftStickDeadzone); rightStickInUse = (padState.rightStickAxis.magnitude > rightStickDeadzone && canShoot); if (useRemaining > 0 && canShoot) useRemaining -= Time.deltaTime; aimLine.enabled = ((rightStickInUse && canShoot) || currentShotCharge > 0); if (sonarDelayRemaining > 0 ) { sonarDelayRemaining -= Time.deltaTime; } else if (sonarDelayRemaining <= 0 && haveSonar) { haveSonar = false; particleSystemSonar.Play(); audioSource_misc.Stop(); audioSource_misc.volume = 0.05F; audioSource_misc.PlayOneShot(onSonar); Collider[] hitColliders = Physics.OverlapSphere(transform.position, sonarRange); List<Vector3> blips = new List<Vector3>(); foreach (Collider c in hitColliders) { bool isVisible = false; foreach (MeshRenderer m in c.gameObject.GetComponentsInChildren<MeshRenderer>()) { if (m.enabled) { isVisible = true; break; } } if (isVisible) { Activator_OnSonar activator = c.gameObject.GetComponent<Activator_OnSonar>(); Activator_GroundButton activatorGb = c.gameObject.GetComponent<Activator_GroundButton>(); if (activator != null) { activator.Activate(); } else if (activatorGb != null) { activatorGb.Activate(); } } else { if (c.gameObject.layer != LayerMask.NameToLayer("Hidden KeyObjects")) continue; blips.Add(c.transform.position); } } Sonar(blips.ToArray()); hitColliders = Physics.OverlapSphere(transform.position, pushRange); List<EnemyInfo> hitEnemies = new List<EnemyInfo>(); foreach (Collider c in hitColliders) { EnemyInfo hitEnemy = c.GetComponent<EnemyInfo>(); if (Vector3.Distance(transform.position, c.transform.position) < pushRange && hitEnemy != null) { hitEnemies.Add(hitEnemy); } } Push(hitEnemies.ToArray(), pushForce); } //Rotates player to face in the direction of the right stick, if right stick not applied, faces same direction as before float aimAngle = 0; if (currentShotCharge <= 0) { if (canShoot) { slingshotLineRenderer.SetVertexCount(2); slingshotLineRenderer.SetPosition(0, slingshotEnds[0].position); slingshotLineRenderer.SetPosition(1, slingshotEnds[1].position); } } if (rightStickInUse || currentShotCharge > 0) { if (!rightStickInUse && currentShotCharge > 0) { aimAngle = Mathf.Atan2(lastRightStickPosition.x, lastRightStickPosition.y) * Mathf.Rad2Deg; } else if (rightStickInUse) { aimAngle = Mathf.Atan2(padState.rightStickAxis.x, padState.rightStickAxis.y) * Mathf.Rad2Deg; } if (canShoot) { slingshotLineRenderer.SetVertexCount(3); slingshotLineRenderer.SetPosition(0, slingshotEnds[0].position); slingshotLineRenderer.SetPosition(1, leftHand.position); slingshotLineRenderer.SetPosition(2, slingshotEnds[1].position); } } barrelEnd.rotation = Quaternion.AngleAxis(aimAngle, barrelEnd.up); //Animations if (leftStickInUse) lastLeftStickPosition = padState.LeftStickAxis; if (rightStickInUse) lastRightStickPosition = padState.rightStickAxis; Vector2 tempLeftStickAxis = padState.LeftStickAxis; Vector2 tempRightStickAxis = padState.rightStickAxis; if (tempRightStickAxis == Vector2.zero && currentShotCharge > 0) tempRightStickAxis = lastRightStickPosition; if (tempLeftStickAxis == Vector2.zero) tempLeftStickAxis = lastLeftStickPosition; float vertical = tempLeftStickAxis.magnitude; if (Vector2.Angle(tempLeftStickAxis, tempRightStickAxis) > 91) { vertical = -vertical; } if (!leftStickInUse) vertical = 0; float horizontal = 0; float leftAngle = Vector2.Angle(new Vector2(0, 1), tempLeftStickAxis); if (tempLeftStickAxis.x < 0) leftAngle = 360 - leftAngle; if (tempRightStickAxis == Vector2.zero || !canShoot) { horizontal = 0; } else { float rightAngle = Vector2.Angle(tempLeftStickAxis, tempRightStickAxis); Vector2 refVec = new Vector2(Mathf.Sin((leftAngle + 90) * Mathf.Deg2Rad), Mathf.Cos((leftAngle + 90) * Mathf.Deg2Rad)); float relativeAngle = (rightAngle / 90); if (Vector2.Angle(refVec, tempRightStickAxis) < 90) { if (vertical > 0) { horizontal = relativeAngle; } else if (vertical < 0) { horizontal = 1 - (relativeAngle - 1); horizontal = -horizontal; } else if (vertical == 0) { horizontal = relativeAngle; if (oppositeRotation) horizontal = relativeAngle - 2; } } else { if (vertical > 0) { horizontal = -relativeAngle; } else if (vertical < 0) { horizontal = 1 - (relativeAngle - 1); } else if (vertical == 0) { horizontal = -relativeAngle; if (oppositeRotation) { horizontal = 1 - (relativeAngle - 1); } } } } animator.SetBool("RightStickInUse", ((rightStickInUse || currentShotCharge > 0) && canShoot)); animator.SetFloat("Vertical", vertical); animator.SetFloat("Horizontal", horizontal); //Shoot if right trigger is pulled enough if (canShoot && player.canShoot) { if (padState.RightTrigger > rightTriggerDeadzone && (rightStickInUse || currentShotCharge > 0)) { //XInputDotNetPure.GamePad.SetVibration(PlayerIndex.One, (currentShotCharge / maxShotChargeTime) * rumbleSensivity, (currentShotCharge / maxShotChargeTime) * rumbleSensivity); if (!shotChargeSoundIsPlaying) { audioSource_shooting.PlayOneShot(isChargingShot, soundVolume); shotChargeSoundIsPlaying = true; } if (shotChargeSoundIsPlaying && !audioSource_shooting.isPlaying) shotChargeSoundIsPlaying = false; currentShotCharge += Time.deltaTime; if (currentShotCharge > maxShotChargeTime) { if (!speedIndicSling.isPlaying) speedIndicSling.Play(); currentShotCharge = maxShotChargeTime; audioSource_shooting.Stop(); shotChargeSoundIsPlaying = false; } else { if (speedIndicSling.isPlaying) { speedIndicSling.Clear(); speedIndicSling.Stop(); } } } else if (currentShotCharge > 0) { if (currentShotCharge > minShotChargeTime) { shotChargeSoundIsPlaying = false; audioSource_shooting.Stop(); audioSource_shooting.PlayOneShot(onShotRelease, soundVolume); GameData.ShotType shotType; if (currentShotCharge == maxShotChargeTime) { shotType = GameData.ShotType.Charged; } else shotType = GameData.ShotType.Normal; Shoot(shotType); currentShotCharge = 0; } else { currentShotCharge = 0; } //XInputDotNetPure.GamePad.SetVibration(PlayerIndex.One, 0, 0); if (shotChargeSoundIsPlaying) audioSource_shooting.Stop(); if (speedIndicSling.isPlaying) { speedIndicSling.Clear(); speedIndicSling.Stop(); } } animator.SetFloat("ShotCharge", currentShotCharge); } else { if (speedIndicSling.isPlaying) { speedIndicSling.Clear(); speedIndicSling.Stop(); } } //Use closest item to the player that is within use range if (padState.B && useRemaining <= 0) { Collider[] hitColliders = Physics.OverlapSphere(transform.position, useRadius); InteractableObject closestObj = null; float distance = float.MaxValue; foreach (Collider c in hitColliders) { float magnitude = (transform.position - c.transform.position).sqrMagnitude; InteractableObject io = c.GetComponent<InteractableObject>(); if (magnitude < distance && io != null) { distance = magnitude; closestObj = io; } } if (closestObj != null) { Use(closestObj); } useRemaining = useCooldown; } //Sonar if (padState.LeftTrigger > leftTriggerDeadzone && player.canSonar) { haveSonar = true; sonarDelayRemaining = sonarDelay; player.Sonar(); animator.SetTrigger("Sonar"); } //Try to absorb color from underneath you, if you are not doing anything else, and you have capacity to absorb if (padState.A && padState.LeftTrigger < leftTriggerDeadzone && padState.RightTrigger < rightTriggerDeadzone && drainGroup != null) { currentDrainAccel += drainSpeedAccel * Time.deltaTime; if (currentDrainAccel > maxDrainSpeed) currentDrainAccel = maxDrainSpeed; actualDrainSpeed = Mathf.Lerp(actualDrainSpeed, maxDrainSpeed, currentDrainAccel); if (player.Drain(drainGroup.splats.Count * actualDrainSpeed * Time.deltaTime)) { if (!particleDrain.isPlaying) particleDrain.Play(); drainGroup.Drain(actualDrainSpeed); if (!audioSource_draining.isPlaying) { audioSource_draining.volume = 0.05F; audioSource_draining.PlayOneShot(isDraining); } } else { if(audioSource_draining.volume <= 0) { if (audioSource_draining.isPlaying) audioSource_draining.Stop(); } else { audioSource_draining.volume -= 0.02F; } if (particleDrain.isPlaying) particleDrain.Stop(); } } else { if (audioSource_draining.volume <= 0) { if (audioSource_draining.isPlaying) audioSource_draining.Stop(); } else { audioSource_draining.volume -= 0.02F; } actualDrainSpeed = 0; player.StopDraining(); if (particleDrain.isPlaying) particleDrain.Stop(); } if (padState.Start) { gameController.PauseGame(); } }
public void RemoveFromSplats(Painting painting) { if (isDead || isLocked) return; if (!splatsUnderPlayer.Contains(painting)) return; splatsUnderPlayer.Remove(painting); if (splatsUnderPlayer.Count == 0) { drainGroup = null; return; } bool isStillInSameSplatGroup = false; foreach (Painting p in splatsUnderPlayer) { if (p.splatGroup == drainGroup) { isStillInSameSplatGroup = true; break; } } if (!isStillInSameSplatGroup) { drainGroup = splatsUnderPlayer[0].splatGroup; } }
void AddToGroup(SplatGroup group) { transform.parent = group.transform; splatGroup = group; group.splats.Add(this); }
public void AddToSplats(Painting painting) { if (isDead || isLocked) return; if (splatsUnderPlayer.Contains(painting)) return; splatsUnderPlayer.Add(painting); if (drainGroup == null) { drainGroup = painting.splatGroup; } }
void idle() { if(curHealth >= startHealth) { returnToMama = true; state = states.move; } else { GameObject wallToHide = null; SplatGroup[] splats = GameObject.FindObjectsOfType<SplatGroup>(); GameObject[] walls = GameObject.FindGameObjectsWithTag("Wall"); foreach(GameObject wall in walls) { if(wall.layer == LayerMask.NameToLayer("Default")) { wallToHide = wall; break; } } if(wallToHide != null) { foreach (SplatGroup splat in splats) { if(mySplat == null) { mySplat = splat; } else { if(Vector3.Distance(wallToHide.transform.position,splat.transform.position) < Vector3.Distance(wallToHide.transform.position,mySplat.transform.position)) { mySplat = splat; } } } } else { foreach (SplatGroup splat in splats) { if (mySplat == null) { mySplat = splat; } else { if (Vector3.Distance(transform.position, splat.transform.position) < Vector3.Distance(transform.position, mySplat.transform.position)) { mySplat = splat; } } } } if(mySplat != null) { state = states.move; } } }