update level and animations

This commit is contained in:
2023-06-20 23:35:39 +03:00
parent 8e026f90cf
commit cdd7db6114
17 changed files with 1389 additions and 187 deletions
+30 -10
View File
@@ -14,33 +14,38 @@ public class PlayerController : MonoBehaviour
private float distance;
private bool _isOnLadder;
private Rigidbody2D _body;
private CapsuleCollider2D _capsule;
private BoxCollider2D _boxCollider;
private bool _isFall;
void Start()
{
_body = GetComponent<Rigidbody2D>();
_capsule= GetComponent<CapsuleCollider2D>();
_boxCollider= GetComponent<BoxCollider2D>();
}
void Update()
{
float moveX = Input.GetAxisRaw("Horizontal");
animator.SetFloat("Horizontal", moveX);
float moveX = 0;
float moveY = 0;
var groundCheck = Physics2D.CapsuleCast(_capsule.bounds.center,_capsule.bounds.size,CapsuleDirection2D.Vertical,0f, Vector2.down, .1f,groundLayer);
var groundCheck = Physics2D.BoxCast(_boxCollider.bounds.center,_boxCollider.bounds.size,0f, Vector2.down, .1f,groundLayer);
if (groundCheck || _isOnLadder)
{
var ladderCheck = Physics2D.CapsuleCast(_capsule.bounds.center, _capsule.bounds.size, CapsuleDirection2D.Vertical, 0f, Vector2.down, .1f, ladderLayer);
if (ladderCheck)
_isFall =false;
moveX = Input.GetAxisRaw("Horizontal");
animator.SetFloat("Horizontal", moveX);
if (IsLadder(Vector2.down))
{
_isOnLadder = true;
moveY = Input.GetAxisRaw("Vertical");
if(moveY> 0)
{
if(!Physics2D.CapsuleCast(_capsule.bounds.center, _capsule.bounds.size, CapsuleDirection2D.Vertical, 0f, Vector2.up, .1f, ladderLayer))
if (!IsLadder(Vector2.up))
{
moveY= 0;
moveY = 0;
}
}
}
@@ -50,6 +55,16 @@ public class PlayerController : MonoBehaviour
}
_body.velocity = new Vector2(moveX * MovementSpeed, moveY * MovementSpeed);
}
else
{
_isFall = true;
print("Falling");
}
}
private RaycastHit2D IsLadder(Vector2 direction)
{
return Physics2D.BoxCast(_boxCollider.bounds.center, _boxCollider.bounds.size, 0f, direction, .1f, ladderLayer);
}
private void FixedUpdate()
@@ -61,7 +76,12 @@ public class PlayerController : MonoBehaviour
}
else
{
_body.gravityScale = 5;
_body.gravityScale = 1;
}
if (_isFall)
{
_body.velocity = new Vector2(0, _body.velocity.y);
animator.SetFloat("Horizontal", 0);
}
}
}