I have been implementing a tutorial I found on youtube. Its a simple 2D game and allows you to move a sprite around the screen as follows:
Vector2 movementVector = new Vector2 (Input.GetAxisRaw ("Horizontal"), Input.GetAxisRaw ("Vertical"));
if (movementVector != Vector2.zero)
{
_anim.SetFloat("inputX", movementVector.x);
_anim.SetFloat("inputY", movementVector.y);
}
Now I’m trying to introduce ray casting, and I think my Z index is causing me problems. I don’t rotate on z axis at any point, so when I try to ray cast it points “up” (away from the screen in the 3d view).
How do I make it point forward (in the direction the sprite is facing) on a 2D plain? I get the impression this gets asked a lot but I’m having trouble implementing a fix.
I’m using the unity docs but I’ve hit a road block. This is the sort of code I’m aiming for:
Physics2D.Raycast(transform.position, transform.forward, 10f);
Vector3 forward = transform.TransformDirection(Vector3.forward) * 10;
Debug.DrawRay(transform.position, forward, Color.green);
Here’s the tutorial I’m using for full reference: