[SOLVED](3D) Shooting RayCast projectile and his hit position on the walls and floors

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

Hi,…so far I have a half working script but not the main result
…hit position of the raycast projectile/laser and the appearance some sparks or bullet holes on this position.
This function shoot ray from RayCast node if shoot button is pressed

func shoot_ray():
        if shooting == true:
             ray_projectile.set_cast_to(Vector3(0, 0, -150))
             ray_projectile.force_ray_cast_update()

Then function shoot

func shoot(delta):
        var point = ray_projectile.get_collision_point().normalized ()
        var space_state = get_world().direct_space_state
        var raycast_from = ray_projectile.global_transform.origin
        var raycast_to = ray_projectile.global_transform.xform(point)
        var ray_result = space_state.intersect_ray(raycast_from, raycast_to, [self])
        if Input.is_action_just_pressed("shoot"):
             shooting = true
             shoot_ray()
             print(raycast_to)
             if ray_projectile.is_colliding():
                   collider = ray_projectile.get_collider()
                   var hit_new = hit.instance() #spawning wall/floor particle hit Sparks
                   collider.add_child(hit_new)
                   print(collider)

…then shoot(delta) function is executed in the _physics_process(delta):
I’m close…I think…results from prints : print(raycast_to) = (-0, 50.203892, 166.345383)
and it changes but I do not know if it’s right.
print(collider) = [StaticBody:1028] and works…rays detect each staticbody perfectly.
…so I have script half-working…hit/sparks will appear on the right wall and floor but always in the middle and not where the aiming cross/raycast node is shooting.
…so many Thanks for any help.

You are just attaching child to wall/floor, without setting position so it’s in the center of parent.

Oen44 | 2018-11-01 15:20

Yeah,…somehow I did not get that…just dislocate this piece var point = ray_projectile.get_collision_point() below collider.add_child(hit_new) and
update position hit_new.global_transform.origin = point of the hit_new instance to the end of the shoot function.

Bishop | 2018-11-02 10:26