Question by
stanlovessoifon · Aug 16, 2018 at 06:02 PM ·
c#2draycastunityeditorvisual studio
Two Raycast2D on object cancel each other out
RaycastHit2D isGround = Physics2D.Raycast(_owner.groundCheck.position, Vector2.down, _owner.distance);
if (isGround.collider == false)
{
if (_owner.moveDir == 1)
{
_owner.moveDir = -1;
}
else
{
_owner.moveDir = 1;
}
}
RaycastHit2D isWall = Physics2D.Raycast(_owner.wallCheck.position, new Vector2 (_owner.moveDir, 0), _owner.wallDistance);
if (isWall.collider == true)
{
if (_owner.moveDir == 1)
{
_owner.moveDir = -1;
}
else
{
_owner.moveDir = 1;
}
}
after the first raycast conditions are filled the 2nd one will not work no matter what, and it doesn't matter which activates first the one that activates 2nd just fails to turn the character. I have tried putting Debug.Logs on them and those still show up so the Raycast are registering, they just wont turn my character around. Any ideas how to fix this?
RaycastHit2D isGround = Physics2D.Raycast(_owner.groundCheck.position, Vector2.down, _owner.distance);
if (isGround.collider == false)
{
if (_owner.moveDir == 1)
{
_owner.moveDir = -1;
}
else
{
_owner.moveDir = 1;
}
}
RaycastHit2D isWall = Physics2D.Raycast(_owner.wallCheck.position, new Vector2 (_owner.moveDir, 0), _owner.wallDistance);
if (isWall.collider == true)
{
if (_owner.moveDir == 1)
{
_owner.moveDir = -1;
}
else
{
_owner.moveDir = 1;
}
}
no matter which one actiaves first the second one will not work, though Debug.Log will still display if I add it, My character just wont turn around.
any idea of how to fix?
Comment