How to implement rotation of an object using coordinates (SOLVED)

Hi! i want to implement rotation of an object to another object

I use this script

local myPos;
local targetPos;

function init(self)
	myPos = go.get_position(hash("/go2"))
	targetPos = go.get_position(hash("/go1"))
	local dir = vmath.normalize(myPos - targetPos);
	local angle = math.deg(math.atan2(dir.x,dir.y))-90
	go.set("/go2","euler.z",angle)
	print(angle)
end

and it works, but not quite


on unity it works

I fix it

local myPos;
local targetPos;
function init(self)
	myPos = go.get_position(hash("/go2"))
	targetPos = go.get_position(hash("/go1"))
	local angle = math.atan2( targetPos.y - myPos.y,targetPos.x - myPos.x)
	go.set("/go2", 'rotation', vmath.quat_rotation_z(angle))
	print(angle)
end
3 Likes