Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | swipis | |
Old Version | Published before Godot 3 was released. |
hi guys!
Need some help with script. So I trying to shoot ray when I press mouse button, here is the code:
func _input(event):
if event.type == InputEvent.MOUSE_BUTTON and event.pressed and event.button_index == 1:
ray_from = self.project_ray_origin(event.pos)
ray_to = ray_from + self.project_ray_normal(event.pos) * ray_length
ray.set_cast_to(ray_to)
print(ray_to, " cast_to ", ray.get_cast_to())
if ray.is_colliding():
var col1 = ray.get_collider()
print("colliding with ", col1.get_name())
#if col1.get_name() == "hitbox":
# print("collision detected with: ", col1.get_name())
#else:
# print("no collision detected!")
ray.set_cast_to(Vector3(0,0,0))
print(ray.get_cast_to())
Problem is when I press mouse button once code setting up set_cast_to but not checking collision test, when I press mouse button second time on same coordinates I getting collision test. I thought that on mouse button click will be executed all code not just part of the code,why is that?
thank you