This question was
closed Feb 09, 2018 at 08:35 PM by
mmaalex22112.
Question by
mmaalex22112 · Dec 24, 2017 at 08:46 PM ·
unity 2dunity5physics2dtagphysics.raycast
Unity2D raycast to check for a wall, Issues.
Hello my fellow Unity friends I have an issue.
I'm using a basic blink (teleport) ability which just directly shifts the player's transform. the problem is I have certain walls I don't want the player to be able to teleport through. I'm trying to use the below script to prevent the player when they are at a 1.5 distance from the "Barriers". This distance is the exact blink distance the player can move. Edit: This function is called in a fixed update
If any more information is needed, I have more. Thank you all in advance! :D
public void BarrierCheck()
{
Vector2 fwd = Player.transform.forward;
RaycastHit2D hit = Physics2D.Raycast(transform.position, fwd, 1.5f);
if (hit.collider.tag.Equals("Barrier"))
{
Allowblink = false;
}
}
Comment