Hello, here I present you my modest library for Defold, it is used to easily set the rotation of objects only in degrees or to rotate an object towards another object or position. I would be happy if it ever becomes a real part of the Defold.
-- This is the code for rotating object in degrees: rotate(url, degrees) -- example: rotate(".", 90) -- And this is the code for rotating to another object: rotate(url, url 2) -- url = url adress of object you want to rotate -- url 2 = url adress of object you want to rotate to -- example: rotate(".", "go1")
And there is the full code of my small Lua library:
function rotate(from, to) if tonumber(to) then if to == nil then to = go.get_id() end go.set(from, "euler.z", to) else local direction = go.get_position(to) - go.get_position(from) local rotation = vmath.quat_rotation_z(math.atan2(direction.y, direction.x)) go.set_rotation(rotation, from) end
I hope this will make development easier for you.
I wish you happy Defolding.