//Character needs to be touching a Zipline object public override bool IsApplicable() { if (!m_IsActive && ((Time.time - m_LastZiplineClimbTime < m_ZiplineClimbCoolDown) || m_ControlledCollider.GetVelocity().y > 0.0f)) { return(false); } if (m_CanReleaseZiplineWithInput) { if ((DoesInputExist("ClimbRelease") && GetButtonInput("ClimbRelease").m_IsPressed) || GetDirInput("Move").m_Direction == DirectionInput.Direction.Down) { return(false); } } if (m_ControlledCollider.IsGrounded()) { return(false); } Zipline zipline = null; if (m_IsActive) { zipline = m_CurrentZipline; } else { zipline = FindZipline(); } if (zipline) { if (!m_IsActive) { m_IsSkating = zipline.IsSkateLine(); Vector3 newPoint = zipline.GetClosestPointOnZipline(GetAttachPoint()); Vector3 diff = newPoint - GetAttachPoint(); if (m_ControlledCollider.GetCapsuleTransform().CanMove(diff)) { return(true); } } else { //We might have been blocked from attaching too closely to the zipline. Let's make sure that we can actually attach if (zipline.GetDistToClosestPointOnZipline(GetAttachPoint()) > m_ZiplineReachRadius) { return(false); } Vector3 travelSpeed = zipline.GetTravelVelocity(GetAttachPoint(), m_ControlledCollider.GetVelocity()); if (zipline.GetDistToEnd(GetAttachPoint(), travelSpeed) < zipline.GetLetGoDistance()) { return(false); } return(true); } } return(false); }
//Called whenever this module is started (was inactive, now is active) protected override void StartModuleImpl() { Zipline zipline = FindZipline(); if (zipline) { //Find our zipline, attach ourselves to it from the bottom or top depending on whether or not it is marked as a "skateline" m_CurrentZipline = zipline; m_IsSkating = zipline.IsSkateLine(); Vector3 newPoint = zipline.GetClosestPointOnZipline(GetAttachPoint()); SetAttachPoint(newPoint); } }
Zipline FindZipline() { Zipline best = null; float best_dist = m_ZiplineReachRadius; //Check for ziplines first (lines we hang from), so check around the top of our capsule Vector3 point = m_ControlledCollider.GetUpCenter(); Collider[] results = Physics.OverlapSphere(point, m_ZiplineReachRadius * 2.0f, m_ZiplineMask, QueryTriggerInteraction.Collide); if (results.Length > 0) { for (int i = 0; i < results.Length; i++) { Zipline zipline = results[i].GetComponent <Zipline>(); if (zipline != null && !zipline.IsSkateLine()) { float dist = zipline.GetDistToClosestPointOnZipline(point); if (dist <= best_dist) { best_dist = dist; best = zipline; } } } } //Now check for skatelines (lines we stand on top of), so check around the bottom of our capsule point = m_ControlledCollider.GetDownCenter(); results = Physics.OverlapSphere(point, m_ZiplineReachRadius * 2.0f, m_ZiplineMask, QueryTriggerInteraction.Collide); if (results.Length > 0) { for (int i = 0; i < results.Length; i++) { Zipline zipline = results[i].GetComponent <Zipline>(); if (zipline != null && zipline.IsSkateLine()) { float dist = zipline.GetDistToClosestPointOnZipline(point); if (dist <= best_dist) { best_dist = dist; best = zipline; } } } } return(best); }