Raycast a specific object
Asked Answered
C

1

0

I want to raycast a specific object, but i don't know exactly how, I use this code for the raycast:

if (Physics.Raycast(transform.position, 
                    transform.LookAt("Player"), 
                    transform.forward)
{
    // doSomething
}

if it's possible i like to use a tag (of the object to see)

Competition answered 16/8, 2023 at 20:33 Comment(1)
F
0

See Collider.Raycast.

It will allow you to test a known collider (which can be obtained from any object that has a collider, like target.collider).

Otherwise you can use Layer Masks with Physics.Raycast (see also How do I use layermasks?).

Fielding answered 6/6, 2023 at 2:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.