+1 vote

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.

enter image description here

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:
        cc = clickPos

func _process(delta):
    bul_pos = get_node(bulCo).get_translation() 
    bul_pos +=  Vector3(cc.x,-cc.y,cc.z) * 0.3 * delta

func bullet():
    CountBullet = CountBullet + 1
    var bullet_inst = bullet.instance()

The object flies that up, then directly down if obj2 is next to obj1.

in Engine by (16 points)
edited by

1 Answer

+1 vote
Best answer

To get a vector that points from bul_pos to cc you could do

var direction = cc - bul_pos
direction = direction.normalized()

Then you should be able to move it with

bul_pos +=  direction * 0.3 * delta

I might be wrong though, I'm new to Godot.

by (210 points)
selected by

Big Thanks!!!

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.