Created
May 25, 2015 02:04
-
-
Save LordNed/812185b0a8f5cbd70b9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private bool CheckForLedgeHangStart() | |
{ | |
if (m_controller.CollisionState.HasLedge()) | |
{ | |
// Ensure we can't grab a ledge within a 20th of a second after the last time we let go of one, | |
// so we don't end up sticking to the same ledge. | |
if (m_velocity.y < 0f && Time.time - m_lastLedgeGrabEndTime > 0.2f) | |
{ | |
// Ensure that we're close enough to the top of the ledge. | |
int wholeBlock = Mathf.RoundToInt(transform.position.y); | |
float delta = transform.position.y - wholeBlock; | |
Debug.Log(string.Format("curYTransform {0} floored: {1} delta: {2}", transform.position.y, wholeBlock, delta)); | |
if (delta < 0.05f) | |
{ | |
// Figure out how much X snap we need to move them to make them on the very edge. | |
wholeBlock = Mathf.RoundToInt(transform.position.x); | |
float xDelta = transform.position.x - wholeBlock; | |
m_controller.Move(new Vector3(-xDelta, -delta, 0f)); | |
m_jumpCount = 1; | |
m_velocity = Vector3.zero; | |
m_state = MovementStates.Ledge_Hanging; | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment