This file contains 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
// @NOTE Must be called from FixedUpdate() to work properly | |
void NormalizeSlope () { | |
// Attempt vertical normalization | |
if (grounded) { | |
RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.up, 1f, whatIsGround); | |
if (hit.collider != null && Mathf.Abs(hit.normal.x) > 0.1f) { | |
Rigidbody2D body = GetComponent<Rigidbody2D>(); | |
// Apply the opposite force against the slope force | |
// You will need to provide your own slopeFriction to stabalize movement |