Licence od 75 € Přihlásit se
DE EN FR ES IT CZ

WASD/Arrow movement?

Toto téma je několik let staré. Některé údaje se mohou týkat starší verze Visionaire Studia. Aktuální návody

  1. · 12 years ago
    Is such a thing possible? I'm thinking of making my game a sidescroller since depth and multiple angles for each characters are giving me a serious headache.
  2. Pracujete na hře?

    Bezplatná verze umožňuje až 25 scén na projekt. Pro více scén a pro prodej hry potřebujete licenci.

    Zobrazit licence Vyzkoušet zdarma
  3. · 12 years ago
    Yes, technically this is possible. SimonS previously posted a method for this in an old thread, as to where that thread is in vs forum, I have no clue - probably lost in time or LSpace somewhere! razz

    Basic gist of it was that on key down you keep updating character destination to the end coordinate of the current scene & then on key release you stop the character. Was something along those lines. Actually since vs 4.0 I believe that this can now be refined as it's possible to use lua to get/return the scene/height of the current scene with the new getSize() function.
  4. · 12 years ago
    Since we have a keyhandler now in lua, you can do it purely with lua:
    function switch(c, cases)
      local f
      if (c) then
        f = cases[c] or cases.default
      else
        f = cases.missing or cases.default
      end
      if f then
        if type(f)=="function" then
          return f()
        else
          error("case "..tostring(c).." not a function")
        end
      end
    end
    
    keymask = tonumber("40000000",16)
    eKeyRight = keymask + 79
    eKeyLeft = keymask + 80
    eKeyDown = keymask + 81
    eKeyUp = keymask + 82
    target_pos = {0, 0}
      
    registerEventHandler("keyEvent", "keyHandler")
    function keyHandler(type, char, keycode, mod)
      local oldtarget = {target_pos[1], target_pos[2]}
      if type == eEvtKeyDown then
        switch(keycode, {
          [eKeyRight] = function() target_pos[1] = 1 end, 
          [eKeyLeft] = function() target_pos[1] = -1 end, 
          [eKeyUp] = function() target_pos[2] = 1 end, 
          [eKeyDown] = function() target_pos[2] = -1 end, 
        })
      elseif type == eEvtKeyUp then
        switch(keycode, {
          [eKeyRight] = function() target_pos[1] = 0 end, 
          [eKeyLeft] = function() target_pos[1] = 0 end, 
          [eKeyUp] = function() target_pos[2] = 0 end, 
          [eKeyDown] = function() target_pos[2] = 0 end, 
        })
      end
      if target_pos[1] ~= oldtarget[1] or target_pos[2] ~= oldtarget[2] then
        local newtarget = {}
        if target_pos[1] == 0 then
          newtarget[1] = game.CurrentCharacter.Position.x
        elseif target_pos[1] == -1 then
          newtarget[1] = 0
        else
          newtarget[1] = 1900
        end
    
        if target_pos[2] == 0 then
          newtarget[2] = game.CurrentCharacter.Position.y
        elseif target_pos[2] == -1 then
          newtarget[2] = 1000
        else
          newtarget[2] = 0
        end
        game.CurrentCharacter.Destination = {x = newtarget[1] , y = newtarget[2]}
      end
      return true 
    end
    


    It only works well if the waysystem is rather big, also the character won't walk straight right or but use the waypoints. So not quite optimal, but fits as demonstration.
  5. · 12 years ago
    hmm... I really wish you had added some -- comments to that script.

    You seem to be updating characters position as opposed to updating destination? Thing with updating the position is that it resets character animation to idle on each update no?
  6. · 12 years ago
    Whooooa. I got no understanding nor skills in LUA, but I appreciate the effort. Kinda silly that Visionaire got all sorts of cool stuff on the LUA's side but I can't access them through normal means in events and such.
  7. · 12 years ago
    The script is plug & play as far as I'm aware - I've not tested it mind. Create a new script in the script section & paste the script into it, then see what happens. I think Simon is using arrow keys instead of WASD in this script though.

    P.S: I don't think there will be any general support for character movement via keyboard added to VS any time soon, well at least not until controller support is added.

Toto téma je uzavřené, protože tu přes rok nikdo neodpověděl. Svůj dotaz můžete položit v novém tématu.

Nové téma

Opravdu smazat tento příspěvek?