#Raycast is not working as intended

1 messages · Page 1 of 1 (latest)

neat kelpBOT
#

It's hard to answer a programming question without code

Resolving a bug is almost impossible when the question doesn't include any of the buggy code. In order to help fix the problem, answerers are going to have to see what the code is.
Source: https://idownvotedbecau.se/nocode

Please isolate the problematic code and send it as a codeblock. If you don't know how to send a codeblock, type []cb

slender zephyr
neat kelpBOT
#

"It's not working" is not helpful

In order for a question to be answered, it must specify what exactly is wrong. Stating simply that "it doesn't work" is not sufficient.
Source: https://idownvotedbecau.se/itsnotworking

Please elaborate on your question by including all relevant details. What do you think is the problem? Have you tried to fix it? If you have, why didn't that work?

slender zephyr
#

What about this is not working?

#

If the object appears directly at the tip of the gun - maybe the ray is hitting the gun itself. Though it wouldn't really make sense for that to only happen sometimes.

In any case, I would strongly advise against doing stuff like transform.parent.parent. You are locking yourself into a rigid hierarchy structure coding like this, when you could easily remedy it using a Transform field.
And I do feel like this may be part of the problem here.

#

Furthermore to debug raycasts, it is usually a good idea to both debug-log the name of the object you hit, and use Debug.DrawLine to draw a visible line between the start point of the ray, and the point that was hit.