I’m attempting to create a function to make the head of a spine character always turn to face the player character. I can make this work when dealing with normal game objects, but when a game object is referenced within a spine model, nothing happens. I’ve tried printing the rotation value, the value is changing but nothing appears to be happening.
Is this sort of game object inside of spine rotation possible?
Here is my code:
local function lookAtPlayer(self, player_id)
local playerPos = go.get_world_position( player_id)
local head = spine.get_go("#spinemodel", "head")
local headPos = go.get_world_position(head)
local rotation = vmath.quat_rotation_z(0)
rotation = vmath.quat_rotation_z( math.atan2(playerPos.y - headPos.y, playerPos.x - headPos.x))
go.set_rotation(rotation, head)
end
I know there is a way to do this with IK Constraints, but I cannot afford that at the moment, so I am attempting a work around.