+1 vote

New to GDScript, I want to make a 3D object follow the mouse on one axis.
I've searched for a while now and really can't find any answers so I'm asking here. Thank you!

in Engine by (13 points)

If by follow, you mean to to it's position, you gotta use navigation. I won't describe that, read the documentation about it. As for getting the position of the cursor in 3d, you gotta raycast from the camera. I advise you to read up about recasting for that

1 Answer

+1 vote

not sure how correct this is but this is how I did it, was only trying to map x axis

func _input(event):
    if event is InputEventMouseMotion:
        var mouse_position = get_viewport().get_mouse_position()
        var new_pos = self.get_viewport().get_camera().project_position(mouse_position, self.translation.y)
        move_and_collide(Vector3(new_pos.x-self.translation.x, 0, 0))
by (16 points)
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 Frequently asked questions and 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 [email protected] with your username.