private void OnCollided(TreeCollider.CollisionInfo colInfo) { if (!colInfo.isTrigger && colInfo.collisionState == TreeCollider.CollisionInfo.CollisionState.enter && !colInfo.collidedWith.tag.Equals("Arrow")) { HealthController hitHealth = colInfo.collidedWith.GetComponentInParent <HealthController>(); if (hitHealth != null) { //Need to calculate hurt value hitHealth.HurtValue(maxHurtValue); } Rigidbody hitBody = colInfo.collidedWith.GetComponentInParent <Rigidbody>(); if (hitBody != null) { hitBody.AddForce(previousVelocity, ForceMode.Impulse); } float penetrationAngle = Vector3.Angle(previousForward, previousVelocity.normalized); DebugPanel.Log(name + " puncture angle", penetrationAngle, 5); if (penetrationAngle <= minimumPenetrationAngle) { var contactPoint = colInfo.collision.GetContact(0); Vector3 punctureDirection = previousForward; Debug.DrawRay(contactPoint.point, -punctureDirection, Color.red, 1000); float arrowLength = transform.GetTotalBounds(false, false).size.z; Vector3 stuckPosition = contactPoint.point - punctureDirection * arrowLength; SetStuck(stuckPosition, punctureDirection, colInfo.collidedWith.transform); } } }
private void Arrow_onArrowHit(ArrowController caller, TreeCollider.CollisionInfo ci) { var bird = ci.collidedWith.GetComponentInParent <BirdController>(); if (bird != null) { StatsViewController.SetScore(++totalScore); StatsViewController.SetArrowsHit(++totalArrowsHit); } }
public void OnBoundaryTriggerStay(TreeCollider.CollisionInfo colInfo) { //Debug.Log("Trigger staying"); var otherJigBoundary = colInfo.collidedWith.GetComponent <JigBoundaryCollider>(); var otherJigPiece = colInfo.collidedWith.GetComponentInParent <JigPieceBehaviour>(); if (otherJigBoundary != null && otherJigPiece != null && justUngrabbed && GrabbableSelf.GetGrabCount() <= 0 && otherJigPiece.GrabbableSelf.GetGrabCount() <= 0) { onAttachAttempt?.Invoke(colInfo.sender.GetComponent <JigBoundaryCollider>(), otherJigBoundary); } }
private void OnCollided(TreeCollider.CollisionInfo colInfo) { if (!colInfo.isTrigger && colInfo.collidedWith.tag.Equals("Arrow")) { var arrow = colInfo.collidedWith.GetComponentInParent <ArrowController>(); if (arrow != null && arrow.GetStuckTarget().root == transform) { arrow.scoreTarget = GetScore(arrow.GetTipPosition()); DebugPanel.Log("Arrow hit target", arrow.scoreTarget.score, 3); var scoresPool = PoolManager.GetPool("ScoresPool"); scoresPool.Get <FlyingScoreController>(score => { score.transform.position = transform.position; score.scoreLabel.text = arrow.scoreTarget.score.ToString(); StartCoroutine(CommonRoutines.WaitToDoAction(success => { scoresPool.Return(score.transform); }, score.ttl)); }); } } }
private void Arrow_onArrowHit(ArrowController caller, TreeCollider.CollisionInfo ci) { var target = ci.collidedWith.GetComponentInParent <TargetController>(); if (target != null) { lastTargetShown = float.MinValue; //If playing random targets, this will make the next target appear var scoreTarget = caller.scoreTarget; if (scoreTarget != null) { totalScore += scoreTarget.score; } else { Debug.LogError("Could not get score from arrow on target"); } StatsViewController.SetScore(totalScore); StatsViewController.SetArrowsHit(++totalArrowsHit); } }
private void OnCollided(TreeCollider.CollisionInfo colInfo) { if (!colInfo.isTrigger && colInfo.collisionState == TreeCollider.CollisionInfo.CollisionState.enter) { #region Health HealthController hitHealth = colInfo.collidedWith.GetComponentInParent <HealthController>(); if (hitHealth != null) { hitHealth.HurtValue(speedPercent * maxHurtValue); } #endregion #region Physics Rigidbody hitBody = colInfo.collidedWith.GetComponentInParent <Rigidbody>(); if (hitBody != null) { hitBody.AddForce(previousVelocity, ForceMode.Impulse); } #endregion #region Score var target = colInfo.collidedWith.GetComponentInParent <TargetController>(); if (target != null) { var contactPoint = colInfo.collision.GetContact(0); scoreTarget = target.GetScore(contactPoint.point); //arrow.scoreTarget = GetScore(arrow.GetTipPosition()); if (scoreTarget != null) { DebugPanel.Log("Arrow hit target", scoreTarget.score, 3); var scoresPool = PoolManager.GetPool("ScoresPool"); scoresPool.Get <FlyingScoreController>(score => { score.transform.position = transform.position; score.transform.forward = transform.forward; score.scoreLabel.text = scoreTarget.score.ToString(); StartCoroutine(CommonRoutines.WaitToDoAction(s => { scoresPool.Return(score.transform); }, score.ttl)); }); } else { DebugPanel.Log("Arrow hit target but somehow without a score", "", 3); } } else { var otherArrow = colInfo.collidedWith.GetComponentInParent <ArrowController>(); if (otherArrow != null) { scoreTarget = otherArrow.scoreTarget; } } #endregion #region Penetration float penetrationAngle = Vector3.Angle(previousForward, previousVelocity.normalized); DebugPanel.Log(name + " puncture angle", penetrationAngle, 5); DebugPanel.Log(name + " speed percent", speedPercent); if (speedPercent > minimumPenetrationSpeedPercent && penetrationAngle <= minimumPenetrationAngle) { PlayPunctureAudio(colInfo.collidedWith.tag); var contactPoint = colInfo.collision.GetContact(0); Vector3 punctureDirection = previousForward; Debug.DrawRay(contactPoint.point, -punctureDirection, Color.red, 1000); SetStuck(contactPoint.point, punctureDirection, colInfo.collidedWith.transform); } else { PlayHitAudio(colInfo.collidedWith.tag); } onArrowHit?.Invoke(this, colInfo); #endregion } }
public void WheelTriggerStay(TreeCollider.CollisionInfo colInfo) { SetPointerPosition(transform.InverseTransformPoint(colInfo.collidedWith.transform.position)); }