better but still have problems
This commit is contained in:
+47
-61
@@ -37,75 +37,61 @@ public abstract class Character : MonoBehaviour
|
|||||||
|
|
||||||
protected void MoveTo(float inputHorizontal, float inputVertical)
|
protected void MoveTo(float inputHorizontal, float inputVertical)
|
||||||
{
|
{
|
||||||
var mapElement = GetMapElement(Vector2.down);
|
var mapElement = GetMapElement(Vector2.down);
|
||||||
|
|
||||||
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
|
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
|
||||||
|
|
||||||
|
if (mapElement == MapElementType.Wall || _isOnLadder || _isOnBridge || mapElement == MapElementType.BreakableWall)
|
||||||
if (mapElement == MapElementType.Wall || _isOnLadder || _isOnBridge || mapElement == MapElementType.BreakableWall)
|
{
|
||||||
|
var leftCheck = GetMapElement(Vector2.left);
|
||||||
|
var rightCheck = GetMapElement(Vector2.right);
|
||||||
|
|
||||||
|
isAllowLeft = !(leftCheck == MapElementType.Wall || leftCheck == MapElementType.BreakableWall);
|
||||||
|
isAllowRight = !(rightCheck == MapElementType.Wall || rightCheck == MapElementType.BreakableWall);
|
||||||
|
|
||||||
|
isAllowVertical = false;
|
||||||
|
_isFalling = false;
|
||||||
|
|
||||||
|
float h_movement =inputHorizontal;
|
||||||
|
if (h_movement > 0 && !_facingRight || h_movement < 0 && _facingRight)
|
||||||
|
{
|
||||||
|
FlipCharacter();
|
||||||
|
}
|
||||||
|
|
||||||
|
SetWalkingAnimation(h_movement != 0);
|
||||||
|
|
||||||
|
var upperElement = GetMapElement(Vector2.up);
|
||||||
|
_isOnLadder = mapElement == MapElementType.Ladder || upperElement == MapElementType.Ladder;
|
||||||
|
|
||||||
|
if (_isOnLadder)
|
||||||
|
{
|
||||||
|
isAllowVertical = true;
|
||||||
|
_isOnLadder = true;
|
||||||
|
|
||||||
|
float v_movement = inputVertical;
|
||||||
|
if (v_movement > 0 && upperElement != MapElementType.Ladder)
|
||||||
{
|
{
|
||||||
var leftCheck = GetMapElement(Vector2.left);
|
v_movement = 0;
|
||||||
var rightCheck = GetMapElement(Vector2.right);
|
|
||||||
if (leftCheck == MapElementType.Wall || leftCheck == MapElementType.BreakableWall)
|
|
||||||
{
|
|
||||||
isAllowLeft = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
isAllowLeft = true;
|
|
||||||
}
|
|
||||||
if (rightCheck == MapElementType.Wall || rightCheck== MapElementType.BreakableWall)
|
|
||||||
{
|
|
||||||
isAllowRight = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
isAllowRight = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
isAllowVertical = false;
|
|
||||||
_isFalling = false;
|
|
||||||
float h_movement = inputHorizontal;
|
|
||||||
if (h_movement > 0 && !_facingRight)
|
|
||||||
{
|
|
||||||
FlipCharacter();
|
|
||||||
}
|
|
||||||
if (h_movement < 0 && _facingRight)
|
|
||||||
{
|
|
||||||
FlipCharacter();
|
|
||||||
}
|
|
||||||
|
|
||||||
SetWalkingAnimation(h_movement != 0);
|
|
||||||
|
|
||||||
var upperElement = GetMapElement(Vector2.up);
|
|
||||||
_isOnLadder = mapElement == MapElementType.Ladder || upperElement == MapElementType.Ladder;
|
|
||||||
if (_isOnLadder)
|
|
||||||
{
|
|
||||||
|
|
||||||
isAllowVertical = true;
|
|
||||||
_isOnLadder = true;
|
|
||||||
v_movement = inputVertical;
|
|
||||||
if (v_movement > 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (upperElement != MapElementType.Ladder)
|
|
||||||
{
|
|
||||||
v_movement = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SetClimbingAnimation(v_movement != 0);
|
|
||||||
}
|
|
||||||
_body.velocity = new Vector2(h_movement * MovementSpeed, v_movement * MovementSpeed);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_isFalling = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetClimbingAnimation(v_movement != 0);
|
||||||
|
_body.velocity = new Vector2(h_movement * MovementSpeed, v_movement * MovementSpeed);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_body.velocity = new Vector2(h_movement * MovementSpeed, _body.velocity.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_isFalling = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MapElementType GetMapElement(Vector2 direction)
|
private MapElementType GetMapElement(Vector2 direction)
|
||||||
{
|
{
|
||||||
var raycastHit = Physics2D.BoxCast(_boxCollider.bounds.center, _boxCollider.bounds.size, 0f, direction, 0.2f, _mapLayer);
|
var raycastHit = Physics2D.BoxCast(_boxCollider.bounds.center, _boxCollider.bounds.size, 0f, direction, 0.01f, _mapLayer);
|
||||||
if (raycastHit)
|
if (raycastHit)
|
||||||
{
|
{
|
||||||
var mapElement = raycastHit.transform.GetComponent<MapElement>();
|
var mapElement = raycastHit.transform.GetComponent<MapElement>();
|
||||||
|
|||||||
Reference in New Issue
Block a user