Game Object rotate to point at mouse

I am currently testing some things out with defold and wanted one of my game objects to rotate to always point at the mouse but when I use the code below it just keeps spinning round and round whenever I move the mouse.

function rotateCannon()
    local crossPos = go.get_position("cross_hair")
    AngleRad = math.atan2(crossPos.y - playerPos.y, crossPos.x - playerPos.x);
    angle = math.deg(AngleRad);
    rotNorm = vmath.quat_rotation_z(angle)
    print(angle)
    go.set_rotation(rotNorm, "cannon")
end

could someone please help me figure out why, I am probably just being very stupid. Thanks.

1 Like

Doesn’t matter I discovered I was unnecessary converting the angle to degrees.

2 Likes