Advertisement
SlaskPrask

asdasd

Feb 9th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. if (h * body.velocity.x < maxSpeed)
  2. {
  3. body.AddForce(Vector2.right * h * acualMoveForce);
  4.  
  5. //SLOPES
  6. RaycastHit2D HL = Physics2D.Raycast(new Vector2(gc.bounds.max.x, gc.bounds.min.y), Vector2.right, 0.1f, 1 << LayerMask.NameToLayer("Ground"));
  7. Debug.DrawRay(new Vector2(gc.bounds.max.x, gc.bounds.min.y), Vector2.right * 0.1f, Color.red);
  8.  
  9. if (HL)
  10. {
  11. float slopeAngle = Vector2.Angle(HL.normal, Vector2.up);
  12.  
  13. if (slopeAngle <= maxSlopeAngle)
  14. ClimbSlope((Vector2.right * h * acualMoveForce), slopeAngle);
  15.  
  16. Debug.Log(slopeAngle);
  17. }
  18. }
  19.  
  20. void ClimbSlope(Vector2 force, float slopeAngle)
  21. {
  22. float moveDistance = Mathf.Abs(force.x);
  23. force.y = Mathf.Sin(slopeAngle * Mathf.Deg2Rad) * moveDistance;
  24. force.x = Mathf.Cos(slopeAngle * Mathf.Deg2Rad) * moveDistance * Mathf.Sign(force.x);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement