Skip to content

Instantly share code, notes, and snippets.

@dilmerv
Created March 2, 2015 08:34
Show Gist options
  • Save dilmerv/0b4a33333c5140390a92 to your computer and use it in GitHub Desktop.
Save dilmerv/0b4a33333c5140390a92 to your computer and use it in GitHub Desktop.
//This method goes in your character controller
//CharacterController.cs
void GlueToFloor ()
{
if (Mathf.Abs (move) > 0 || !groundHit || IM.Jump_Button ()) {
this.transform.GetComponent<Rigidbody2D> ().isKinematic = false;
}
else if (groundHit && Mathf.Abs (move) == 0 && !isPlatform) {
this.transform.GetComponent<Rigidbody2D> ().isKinematic = true;
}
}
//Implemented a new extension to check when character touches a platform
//Collision2DExtensions.cs
public static class Collision2DExtensions {
public static bool WithPlatform(this Collision2D self) {
return self.gameObject.tag == "Platform";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment