I got the ray to tell when it cant move working, I have rotation working, I even have the ray rotating correctly. I just cannot think of how to get the character to move forward by 1 unit in the direction it’s facing.
if (Input.anyKeyDown)
{
var FowardRayDistance = 0f;
Vector2 fwd = transform.TransformDirection(Vector2.up);
Vector2 bwd = transform.TransformDirection(Vector2.down);
//Foward Ray
while (FowardRayDistance < maxFowardCheckDistance)
{
RaycastHit2D FHit = Physics2D.Raycast(transform.position, fwd, FowardRayDistance);
RaycastHit2D hit = Physics2D.Raycast(transform.position, bwd, FowardRayDistance);
if (FHit)
{
if (Input.GetKeyDown(KeyCode.W) && FowardRayDistance > 1)
{
}
else if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("hit: " + FHit.collider.name + "| at: " + FowardRayDistance);
}
FowardRayDistance = maxFowardCheckDistance;
}
else
{
FowardRayDistance += 1f;
}
}
}
The if (Input.GetKeyDown(KeyCode.W) && FowardRayDistance > 1)
area is where i know the movement part will go i just dont know what to put there.