Character head angles towards cursor?

  • #1, by JoemcrFriday, 17. October 2014, 19:38 6 years ago
    Hi,

    I recently made this game using Construct 2;

    http://gamejolt.com/games/adventure/unnecessary-sentience-2-...

    In this game the main characters head spins around to remain angled towards the cursor during gameplay - so he looks where you point. I was wondering if anyone might be able to help me get this effect working in Visionaire?

    In the Construct 2 game my main character sprites were made headless, then the head was a separate sprite set to follow the main character and rotate towards the cursor. any chance of doing something like this with lua?

    Any help would be greatly appreciated,

    Thanks,
    Joe

    Newbie

    96 Posts


  • #2, by afrlmeFriday, 17. October 2014, 20:21 6 years ago
    hmm not sure it could be done exactly as you have it in that game but you could check add the head as a scene object & use a bit of math to position & scale it. Since VS 4.1 you can now rotate & scale objects & I already wrote a script that can get the angle between 2 points which you could use to control the rotation. You would need 2 objects for the face facing one way & another for the other direction, or 1 object & 2 animations.

    I believe it is possible to a degree. By the way, your game looks pretty whacky.

    Question: will the character scale up & down or will the scale be fixed? The reason I'm asking is because if the character scales then it will require additional math to determine the position the head should be. Also quick note: positioning of animations, objects & images is done with the top-left pixel in Visionaire Studio but character position is based on the animation/character center you add to each of the character animations.

    P.S: I noted the headlamp was a petzl. mine is a bit worse for wear. feckin' rubber button came off & now it's hard to turn on/off.

    P.P.S: just finished the demo. Was pretty funny in a morbid sort of way. Graphics were very strange & surreal. By the way you can now achieve various lighting effects with Visionaire Studio 4.1 such as spotlights & flashlight, saturation & much more since Simon added openGL 2.0 shader support.

    http://wiki.visionaire-tracker.net/wiki/AlignChar_(CMS) & http://wiki.visionaire-tracker.net/wiki/AlignObj_(CMS) - alignment scripts I was talking about.

    Imperator

    6812 Posts

  • #3, by NigecSaturday, 18. October 2014, 12:45 6 years ago
    the guy is doing a VS version of the game, well the same character, can't recall his name off hand but he recently posted a kickstarter campaign

    https://www.visionaire-studio.net/forum/thread/unnecessary-s...

    Key Killer

    547 Posts

  • #4, by afrlmeSaturday, 18. October 2014, 13:27 6 years ago
    Yeah mate I know. I played the game he made with construct 2 last night. Was pretty messed up with a strange graphic style. I liked the character styles because I found them fun but wasn't so keen on all the background/scene object graphics (personal pref).

    I believe he can achieve the same sort of style & gameplay as seen in his game with construct2, albeit we don't have as many effects as construct2 yet but Simon has steadily been increasing the effects we do have & improving on some of them too.

    I downloaded construct to have a little look over it & it seems very nice. It has a nice enough gui & it has a lot of features we are currently missing such as advanced audio control & effect modules & I believe it also allows the developer to add various effects to assets which I believe Simon is looking into for VS also. Both of the things I mentioned are things that I would like to see.

    There's a lot of other nice stuff in construct 2 such as additional platform support, multiple control input support & a physics engine (what ever could we do with a physics engine in a 2D adventure game you ask? I'm not sure yet but I'm sure I'll be able to think of something...)

    The only real downside for me is the lack of scripting editor, I prefer to script when possible as I find it easier than clicking here, there, left, right & center like some madman possessed. I find opening up dialog boxes, scrolling down lists & selecting actions/events to be very time consuming & they kill my work-flow & concentration.

    Imperator

    6812 Posts

  • #5, by NigecSaturday, 18. October 2014, 13:37 6 years ago
    shit.. I didn't clock it was Joe ASKING the question FFS! I must be getting old :/

    Key Killer

    547 Posts

  • #6, by afrlmeSaturday, 18. October 2014, 13:48 6 years ago
    haha I think you need to get some stronger specs Nige! grin

    Imperator

    6812 Posts

  • #7, by NigecSaturday, 18. October 2014, 14:02 6 years ago
    Particles with physics would be cool, something turning could ease to a stop, spinning something is easier

    There was a bit of selective reading involved I think lol.. very selective in this case <blush>

    I love the style Joe, and your animations, I wish I had the money and story to enlist your skills

    Key Killer

    547 Posts

  • #8, by afrlmeSaturday, 18. October 2014, 14:12 6 years ago
    Ah yeah good idea. A physics engine would be awesome for particles. We can already rotate scene objects with easing using a combination of startObjectTween & the new rotation data structure table.
    -- note: reverse only works if loop is enabled. (reverse means play forward then backwards)
    -- note: loop amount can be increased by adding higher rotation value. i.e: 720 will rotate 2x
    -- note: rotation can also be done in the opposite direction by using a negative value. i.e: -180
    -- example: rotateObject("granny", 100, 170, 3000, easeQuintOut, false, false)

    function rotateObject(obj, scale, degree, delay, easing, reverse, loop)
    obj = Objects[obj]
    obj.RotationCenter = {x = -1, y = obj.ObjectSprite.SpriteSprite:getPosition().y}
    obj.Rotation = obj.Rotation; obj.Scale = obj.Scale
    scale = (scale / 100) -- convert scale percent to decimal
    degree = (degree * math.pi) / 180 -- convert degree to radian
    obj:to(delay, {Rotation = degree, Scale = scale}, easing, loop, reverse)
    end

    local deg = 43

    local a = (deg / 360) * (2 * math.pi)
    local b = (deg * math.pi) / 180
    print(a, b)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

    ...workflow function I've not added to the wiki yet & also a couple of math degree conversion tests.

    Imperator

    6812 Posts

  • #9, by NigecSaturday, 18. October 2014, 14:25 6 years ago
    Nice one Lee smile

    Key Killer

    547 Posts

  • #10, by JoemcrSaturday, 18. October 2014, 17:05 6 years ago
    Hi guys,

    Thanks for your help. Unfortunately I have no grasp of scripting whatsoever, and the links you have kindly provided only served to confuse me further. I was hoping there might be some more simple solution.

    Not sure I want to use this effect again anyway – was just planning to try it out and see how it look in the context of my new game. I think I will return to the more conventional static head for now!

    Thanks,
    Joe

    Newbie

    96 Posts

  • #11, by afrlmeSaturday, 18. October 2014, 17:50 6 years ago
    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})
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14

    ...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.

    Imperator

    6812 Posts

Write post