I'm trying to program 2D mouse aim, where the arms and the gun in the arms rotates to point at the mouse. But for some reason, the arms and gun rotate and do not follow the mouse position.

The each of the arms and the guns are separate node that are parented to an orbit node that is located on at the shoulder of the arms.

The following code is script that is attached and running on the orbit.

    var mousePos = get_viewport().get_mouse_pos();
    var dir = get_pos();
    var angle = (atan2(dir.x,dir.y))+(2*PI);
    var arm_gun_dir = gravGun_Ref.get_pos()-get_pos();
    var arm_gun_angle = (atan2(arm_gun_dir.x,arm_gun_dir.y))+(2*PI);

Here is a GIF of the result of this setup: enter image description here

Here is an image showing where the positions of the upper arm and the gun.

enter image description here

  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – user1430
    Jan 3, 2017 at 17:18


You must log in to answer this question.

Browse other questions tagged .