public void OnHit(BallBehaviour _ball, Vector3 _impactVector, PawnController _thrower, float _damages, DamageSource _source, Vector3 _bumpModificators = default(Vector3)) { if (_ball != null) { if (_ball.isGhostBall) { return; } } if ((_source == DamageSource.Ball | _source == DamageSource.Dunk) & !shutDown) { if (MomentumManager.GetMomentum() >= puzzleData.nbMomentumNeededToLink) { if (fX_Linked != null) { Destroy(fX_Linked); } if (fX_LinkEnd != null) { Destroy(fX_LinkEnd); } fX_Linked = FeedbackManager.SendFeedback("event.PuzzleLinkActivated", this, transform.position, _impactVector, _impactVector).GetVFX(); if (fX_Activation == null) { fX_Activation = FeedbackManager.SendFeedback("event.PuzzleLinkActivation", this, transform.position, _impactVector, _impactVector).GetVFX(); } MomentumManager.DecreaseMomentum(puzzleData.nbMomentumLooseWhenLink); chargingTime = nbSecondsLinkMaintained; isActivated = true; myAnim.SetBool("Awaken", true); myAnim.SetBool("IsActivated", true); ActivateLinkedObjects(); } } }
public virtual void Damage(float _amount, bool enableInvincibilityFrame = false) { if (!CanDamage()) { return; } if (enableInvincibilityFrame) { SetInvincible(); } FeedbackManager.SendFeedback(eventOnBeingHit, this, transform.position, transform.up, transform.up); currentHealth -= _amount; if (currentHealth <= 0) { Kill(); } if (isPlayer) { MomentumManager.DecreaseMomentum(MomentumManager.datas.momentumLossOnDamage); } }
private void UpdateBallPosition() { switch (ballInformations.state) { case BallState.Flying: ballInformations.timeFlying += Time.deltaTime; if (ballInformations.isTeleguided) { PassController i_currentPassController = GetCurrentThrower().GetComponent <PassController>(); if (i_currentPassController != null) { ballInformations.direction = (i_currentPassController.GetTarget().GetCenterPosition() - transform.position).normalized; } } else if (ballInformations.curve != null) { PassController i_currentPassController = GetCurrentThrower().GetComponent <PassController>(); List <Vector3> i_pathCoordinates = i_currentPassController.GetCurvedPathCoordinates(startPosition, i_currentPassController.GetTarget(), ballInformations.initialLookDirection, out float d); float i_curveLength; if (i_currentPassController == null) { return; } ConvertCoordinatesToCurve(i_pathCoordinates, out curveX, out curveY, out curveZ, out i_curveLength); ballInformations.maxDistance = i_curveLength; float i_positionOnCurve = ballInformations.distanceTravelled / ballInformations.maxDistance; if (ballInformations.thrower.isPlayer) { LockManager.LockTargetsInPath(i_pathCoordinates, i_positionOnCurve); if (i_positionOnCurve >= 0.95f) { ChangeState(BallState.Grounded); LockManager.UnlockAll(); } } Vector3 i_nextPosition = new Vector3(curveX.Evaluate(i_positionOnCurve + 0.1f), curveY.Evaluate(i_positionOnCurve + 0.1f), curveZ.Evaluate(i_positionOnCurve + 0.1f)); ballInformations.direction = i_nextPosition - transform.position; } if (ballInformations.moveSpeed <= 0) { ballInformations.curve = null; ChangeState(BallState.Grounded); } else { //Ball is going to it's destination, checking for collisions RaycastHit[] i_hitColliders = Physics.RaycastAll(transform.position, ballInformations.direction, ballInformations.moveSpeed * Time.deltaTime); foreach (RaycastHit raycast in i_hitColliders) { /*EnemyShield i_selfRef = raycast.collider.GetComponentInParent<EnemyShield>(); * if (i_selfRef != null) * { * if (i_selfRef.shield.transform.InverseTransformPoint(transform.position).z > 0.0) * { * FeedbackManager.SendFeedback("event.ShieldHitByBall", this); * Vector3 i_newDirection = Vector3.Reflect(ballInformations.direction, i_selfRef.shield.transform.forward); * Bounce(i_newDirection, 1); * } * }*/ IHitable i_potentialHitableObjectFound = raycast.collider.GetComponent <IHitable>(); if (i_potentialHitableObjectFound != null && !hitGameObjects.Contains(i_potentialHitableObjectFound) && !isGhostBall) { hitGameObjects.Add(i_potentialHitableObjectFound); i_potentialHitableObjectFound.OnHit(this, ballInformations.direction * ballInformations.moveSpeed, ballInformations.thrower, GetCurrentDamages(), DamageSource.Ball); SlowTimeScale(); } if (raycast.collider.isTrigger || raycast.collider.gameObject.layer != LayerMask.NameToLayer("Environment")) { break; } FeedbackManager.SendFeedback("event.WallHitByBall", raycast.transform, raycast.point, ballInformations.direction, raycast.normal); if (!ballInformations.canHitWalls) { return; } if (ballInformations.bounceCount < ballInformations.ballDatas.maxBounces && ballInformations.canBounce) //Ball can bounce: Bounce { Analytics.CustomEvent("BallBounce", new Dictionary <string, object> { { "Zone", GameManager.GetCurrentZoneName() }, }); Vector3 i_hitNormal = raycast.normal; i_hitNormal.y = 0; Vector3 i_newDirection = Vector3.Reflect(ballInformations.direction, i_hitNormal); i_newDirection.y = -ballInformations.direction.y; Bounce(i_newDirection, ballInformations.ballDatas.speedMultiplierOnBounce); return; } else //Ball can't bounce: Stop { ChangeState(BallState.Grounded); MomentumManager.DecreaseMomentum(MomentumManager.datas.momentumLossWhenBallHitTheGround); return; } } } transform.position += ballInformations.direction.normalized * ballInformations.moveSpeed * Time.deltaTime * MomentumManager.GetValue(MomentumManager.datas.ballSpeedMultiplier) * GetCurrentSpeedModifier(); ballInformations.distanceTravelled += ballInformations.moveSpeed * Time.deltaTime * MomentumManager.GetValue(MomentumManager.datas.ballSpeedMultiplier) * GetCurrentSpeedModifier(); if (ballInformations.curve == null && !ballInformations.isTeleguided && ballInformations.distanceTravelled >= ballInformations.maxDistance) { ChangeState(BallState.Grounded); } break; } }