Question by
goduster · Nov 08, 2019 at 08:17 PM ·
c#rayraycasthit2d
Please help with raycast2d
So I have this script that should be working. However it doesn't show anything when I press mousebutton(1) or any other mousebutton. Also when I hadn't (&& hit.collider.CompareTag("Untagged") it showed my current player position.
void FixedUpdate() { rb.velocity = playerPosition * moveSpeed;
if (Input.GetMouseButton(1))
{
BlinkAbility();
}
}
public void BlinkAbility()
{
mouseDirection = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
Ray2D ray = new Ray2D(transform.position, mouseDirection);
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, 20f);
if (hit.collider != null)
{
Debug.Log("Target Position: " + hit.transform.position);
Debug.DrawLine(ray.origin, hit.point);
}
}
Comment
Your answer
Follow this Question
Related Questions
Raycasting problem, colliders not being recognized? 1 Answer
Strange Raycast problem 0 Answers
How do I make a laser that bounces around a room? 0 Answers
drag AND drop push and pull object 0 Answers
Need help making a ledge climber. The problem, transform.position always returns to vector( 0, 0) 0 Answers