- Home /
Question by
JeffreyRocks · Oct 23, 2021 at 01:50 AM ·
rigidbody2draycasthit2d
Rigidbody2D and collider don't work
This script works if i don't put a rigidbody2D to my collider. iT GIVES THE TAG NAME OF THE COLLIDER. BUT if i put a rigidbody2D to my collder it doesn't work. and it says 'missed".
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint((Input.GetTouch(0).position)), new Vector3(0,0,1));
if (hit.collider != null)
{
print(hit.collider.tag);
if (hit.collider.tag == "ball")
{
print("hitball");
hit.transform.gameObject.GetComponent<Rigidbody2D>().simulated = true;
}
} else
{
print("miseed");
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Question about raycast collision detection involving Kinematic Rigidbody2D 1 Answer
Back and forth movement using Rigidbody2D.MovePosition() 0 Answers
Modifying a kinematic rigidbody2D.velocity makes player to go through the wall 0 Answers
How to detect wether an object is headed towards the top or bottom of an object? 2 Answers
Make Object lookat velocity 0 Answers