Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (h * body.velocity.x < maxSpeed)
- {
- body.AddForce(Vector2.right * h * acualMoveForce);
- //SLOPES
- RaycastHit2D HL = Physics2D.Raycast(new Vector2(gc.bounds.max.x, gc.bounds.min.y), Vector2.right, 0.1f, 1 << LayerMask.NameToLayer("Ground"));
- Debug.DrawRay(new Vector2(gc.bounds.max.x, gc.bounds.min.y), Vector2.right * 0.1f, Color.red);
- if (HL)
- {
- float slopeAngle = Vector2.Angle(HL.normal, Vector2.up);
- if (slopeAngle <= maxSlopeAngle)
- ClimbSlope((Vector2.right * h * acualMoveForce), slopeAngle);
- Debug.Log(slopeAngle);
- }
- }
- void ClimbSlope(Vector2 force, float slopeAngle)
- {
- float moveDistance = Mathf.Abs(force.x);
- force.y = Mathf.Sin(slopeAngle * Mathf.Deg2Rad) * moveDistance;
- force.x = Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * moveDistance * Mathf.Sign(force.x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement