Instancing objects at RayCast hit points

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By grey_lotus

I have this FPS raycast weapon and I want it that a scene (a particle animation) is instanced at the point where the ray hits an object whenever the shoot( ) function is called. I can’t figure out how to do it. Help please.

:bust_in_silhouette: Reply From: Magso

Both the methods you are needing are in the RayCast docs, is_colliding() and get_collision_point()Note: This point is in the global coordinate system.”

if raycast_node.is_colliding():
    particles.global_transform.origin = raycast_node.get_collision_point()

Yes. I already did something similar before:

if ray.is_colliding():
var collider = ray.get_collider()
var spark_point = spark.instance()
var point = ray.get_collision_point().normalized()
spark_point.global_transform.origin = point

But when I run it and shoot at an object, the scene freezes and I get an error saying "Invalid call. Nonexistent function ‘instance’ in base ‘StreamTexture’

grey_lotus | 2020-03-06 01:29

You can only instance tscn files not resources. Reference the node that uses the resource and use load(spark) to assign it.

Magso | 2020-03-06 11:06