Hey Guys. I’m a bit of a noob and I need some advice since google didn’t help me.
I’m working on a 2D platformer with shooting mechanics, and I’m trying to draw a raycast from the player to my mouse. The problem is, it only points from the player (or rather the used game object inside the player) to the coordinates 0,0. How can I fix that?
I’m using Unity 4.7.1f1 btw. Don’t ask why, I just like it better.
It tells me that it does shoot, but not that it collides with anything (which is not really surprising).
If you need more information, I will provide it as fast as I can!
here’s the code:
void Shoot ()
{
Debug.LogError(“Shoot!”);
Vector2 mousePos = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
Vector2 firePointPos = new Vector2(firePoint.position.x, firePoint.position.y);
RaycastHit2D hit = Physics2D.Raycast(firePointPos, mousePos-firePointPos, 100, whatToHit);
Debug.DrawLine (firePointPos, (mousePos - firePointPos) * 100, Color.cyan);
if (hit.collider != null)
{
Debug.LogError("Collision");
Debug.DrawLine(firePointPos, hit.point, Color.red);
}
}