Hmm the scripts were more as a reference to base a new script on, which showed you how to calculate the angle between 2 points.
I don't think you would achieve this effect without lua script. On glancing over construct2 I see that there was an option which allows you to simply align assets towards the mouse position. If you wanted to simplify it then you could simply do 2 to 3 states & have the head face left, right or towards the camera based on the x position of the mouse away from the characters current position. You would only require one animation for the head in which you could control the frames based on the position that needs to be set.
function onMouseEvent(eventType, mousePosition)
if eventType == eEvtMouseMove then
if getCursorPos().x < game.CurrentCharacter.CharacterPosition.x - 25 then
ActiveAnimations["char_head"].AnimationFirstFrame = 1; ActiveAnimations["char_head"].AnimationLastFrame = 1
elseif getCursorPos().x > game.CurrentCharacter.CharacterPosition.x + 25 then
ActiveAnimations["char_head"].AnimationFirstFrame = 3; ActiveAnimations["char_head"].AnimationLastFrame = 3
else
ActiveAnimations["char_head"].AnimationFirstFrame = 1; ActiveAnimations["char_head"].AnimationLastFrame = 1
end
end
end
registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseMove, eEvtMouseLeftButtonDoubleClick, eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp, eEvtMouseLeftButtonHold, eEvtMouseLeftButtonHolding, eEvtMouseRightButtonDoubleClick, eEvtMouseRightButtonDown, eEvtMouseRightButtonUp, eEvtMouseMiddleButtonDown, eEvtMouseMiddleButtonUp, eEvtMouseWheelUp, eEvtMouseWheelDown})
...untested code (again). This would force the animation frame to 1 if mouse position is 25 pixels or more less than current character position or frame 3 if mouse position is 25 pixels or more than current character position else it would use frame 2 which is face looking towards the camera.
The rotation of the object is a little more complicated I think as the rotation center will be set to the top left pixel of the animation/image by default.
Also off the top of my head, I'm not sure about the math required to correctly position the head onto the character.
Something you could do I suppose is create the head as a character & then place the animation center the same as the main character which in theory should place the characters head in the correct position but the character center might be different for each animation so it's a bit hard to calculate.