Can we use the keyboard for the character movements?

  • #30, by AkcayKaraazmakThursday, 08. October 2015, 10:23 9 years ago
    Ovv it really worked mate and character doesnt pass the borders???

    Great Poster

    440 Posts


  • #31, by AkcayKaraazmakFriday, 09. October 2015, 01:07 9 years ago
    I tried it but character walking is so strange. Walk and turn always and animations jump all the time. I tried 250 and 500 for pause but no luck. Maybe thats because the character is 3d, I dont know.

    Great Poster

    440 Posts

  • #32, by afrlmeFriday, 09. October 2015, 01:30 9 years ago
    Possibly. I recommend waiting until gamepad support is fully implemented as that will probably handle the character movement in a different way to however the current mouse / destination method works.

    Imperator

    7278 Posts

  • #33, by AkcayKaraazmakFriday, 09. October 2015, 09:40 9 years ago
    Yea hope the next release will have this feature

    Great Poster

    440 Posts

  • #34, by CrossSaturday, 10. October 2015, 18:43 9 years ago
    The first stop of the character, that DEshini talks about, is why i put the whole code into another loop. For some reasons then it works fine (it loops faster?). The problem with higher values for movement like +250 is, that the character will not walk to the border of the walkarea, but stop already around 250 pixels before that.

    Newbie

    92 Posts

  • #35, by afrlmeSaturday, 10. October 2015, 19:48 9 years ago
    The first stop of the character, that DEshini talks about, is why i put the whole code into another loop. For some reasons then it works fine (it loops faster?). The problem with higher values for movement like +250 is, that the character will not walk to the border of the walkarea, but stop already around 250 pixels before that.


    Yes the mainLoop event loops a lot faster than the engine loop. mainLoop is approx every 4ms (approx) whereas the engine events loop every 16ms (approx) to make up 60fps.

    Note: the mainLoop timing is a little erratic. I think it all depends on what is happening on the screen, but the timing is usually less than 100ms easy. You could test it by creating a small function that triggers a print function containing time passed say 10 times in a row.

    Create this as an execute script type in the script section then call it inside of a key action (released) or wherever to check the speed of 10 loops. You'll see the time varies. I also tested speed of key event loop & it's not much difference.
    local tmr = 10
    local st = getTime({flags=1, reset=true})
    
    function loopTimer()
     if tmr > 0 then
      print( getTime() ); tmr = tmr -1;  st =getTime({flags=1, reset=true})
     else unregisterEventHandler("mainLoop", "loopTimer")
     end
    end
    
    registerEventHandler("mainLoop", "loopTimer")
    


    * edit: if you want to test the loop time of a key event. Create a key event in the key action tab under game & create an execute a script action part containing...
    print( getTime() ); getTime({flags=1, reset=true})
    

    ... this will print the current time passed, then reset the timer back to 0. The first time will either be 0 or will probably be a large value, so just ignore the first printed value.

    Imperator

    7278 Posts

  • #36, by tristan-kangSunday, 11. October 2015, 20:33 9 years ago
    It's funny because people have been asking keyboard movements more than 3 threads 2 years ago and now it's rather possible but not completely. smile

    Great Poster

    267 Posts

  • #37, by afrlmeSunday, 11. October 2015, 21:33 9 years ago
    Seems like it will be possible in next update. According to team wiki changelog controller support has been fully implemented & Simon said it should be possible to listen / access via Lua also.

    Imperator

    7278 Posts

  • #38, by franzSaturday, 26. January 2019, 22:45 5 years ago
    Hi everyone,

    I write here for keyboard implementation on Lua, because I searched a lot on Visionaire forum but unfortunately the unique Lua script I found does not work properly (my version is 5.0.9). I tried different combinations of way borders (>=2 polygons) and way points (points joint as a spiderweb) but every time i run the game (editor or build) character movement is quite always different and wrong (sometimes there is no movement, other times character can walk over the border). Does it exist a working Lua script for controlling movements character by keyboard/controller? Thank you for your support smile
    I copy Simon Lua script below:

    function keyboardHandler(eventType, character, keycode, modifiers) 
        if eventType==eEvtKeyUp then
            print('key up: ' .. keycode)
            keycode = keycode % 1073741824
            if keycode == 80 then -- left
                charmove_x = 0
            elseif keycode == 79 then -- right
                charmove_x = 0
            elseif keycode == 81 then -- down
                charmove_y = 0
            elseif keycode == 82 then -- up
                charmove_y = 0
            end
            createEvent('eEvtControllerAxisCharacterMove', {x=charmove_x, y=charmove_y},25)
            if keycode == 113 then -- Q
              startAction("Objects[Bicchiere].Actions['Low_Profile' eseguito]")
            end
            if keycode == 119 then -- W
              startAction("Objects[Bicchiere].Actions['High_Profile' eseguito]")
            end
        elseif eventType==eEvtKeyDown then
            print('key pressed: ' .. keycode)
            keycode = keycode % 1073741824
            if keycode == 80 then -- left
                charmove_x = -100
            elseif keycode == 79 then -- right
                charmove_x = 100
            elseif keycode == 81 then -- down
                charmove_y = 100
            elseif keycode == 82 then -- up
                charmove_y = -100
            end
            createEvent('eEvtControllerAxisCharacterMove', {x=charmove_x, y=charmove_y},25)  
        elseif eventType==eEvtControllerKeyUp then
            print('controller up: ' .. keycode)
            if keycode == 1000001 then --controller key A up
                createEvent('eEvtMouseLeftButtonDown')
                createEvent('eEvtMouseLeftButtonUp')
    -- createEvent('eEvtKeyDown',{x=0,y=0},eKeyEscape,0)
            end
        elseif eventType==eEvtControllerKeyDown then
            print('controller down: ' .. keycode)
            if keycode == 1000001 then --controller key A down
            end
        elseif eventType==eEvtControllerAxis then
            if string.match(character, 'RIGHTX') then
                mouse_x = keycode
                createEvent('eEvtControllerAxisMouseMove', {x=mouse_x, y=mouse_y}, 19, 9)
            elseif string.match(character, 'RIGHTY') then
                mouse_y = keycode
                createEvent('eEvtControllerAxisMouseMove', {x=mouse_x, y=mouse_y}, 19, 9)
            elseif string.match(character, 'LEFTX') then
                charmove_x = keycode
                createEvent('eEvtControllerAxisCharacterMove', {x=charmove_x, y=charmove_y}, 25)
            elseif string.match(character, 'LEFTY') then
                charmove_y = keycode
                createEvent('eEvtControllerAxisCharacterMove', {x=charmove_x, y=charmove_y}, 25)
            end
          end
      return false
    end
    registerEventHandler('keyEvent', 'keyboardHandler')


    Newbie

    7 Posts