0 votes

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))

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
             if ray_projectile.is_colliding():
                   collider = ray_projectile.get_collider()
                   var hit_new = hit.instance() #spawning wall/floor particle hit Sparks

....then shoot(delta) function is executed in the physicsprocess(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.

asked Nov 1, 2018 in Engine by Bishop (443 points)
edited Nov 2, 2018 by Bishop

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

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.