Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Oleg Poluhin | |
Old Version | Published before Godot 3 was released. |
Good day to all! I apologize for my English. Please tell me how to make the object move to another object when the button is clicked.
Attached a picture, for example, what you need to do.
Tried to implement it this way:
var cc
func _input_event_enemy(viewport, event, clickPos, click_noraml, shape_idx):
if event.type == InputEvent.MOUSE_BUTTON and event.button_index == BUTTON_LEFT and event.pressed:
bullet()
cc = clickPos
func _process(delta):
get_node(bulCo).show()
bul_pos = get_node(bulCo).get_translation()
bul_pos += Vector3(cc.x,-cc.y,cc.z) * 0.3 * delta
get_node(bulCo).set_translation(bul_pos)
func bullet():
CountBullet = CountBullet + 1
var bullet_inst = bullet.instance()
bullet_inst.set_name("bullet"+str(CountBullet))
add_child(bullet_inst)
get_node("bullet"+str(CountBullet)).hide()
get_node("bullet"+str(CountBullet)).set_translation(Vector3(get_node("/root/Main/PlayerEvent").get_translation()))
return
The object flies that up, then directly down if obj2 is next to obj1.