Resticted Movement?

  • #1, by SDMonoFriday, 24. May 2013, 23:39 11 years ago
    Hi Everyone

    I just have one question... is there any way you can restict the players movement to the X-axes so that the player does not move up or down on the Y-axes?

    Thank you very much!!!

    Forum Fan

    148 Posts


  • #2, by afrlmeSaturday, 25. May 2013, 01:07 11 years ago
    this has been answered in another recent post...

    1. you can create very small (close together) way borders to prevent the player from moving up the y axis.

    2. you can still allow the player to move up some of the y axis & not have him face up/down (or diagonally) or by simply only adding 2 or 6 walk directions (left/right or left/right & diagonal up/down left/right) & if you need the character to face up or down at some point then just create a new outfit for the character with the up/down directions & change to that outfit when needed.

    Imperator

    7278 Posts

  • #3, by SDMonoSaturday, 25. May 2013, 01:23 11 years ago
    Thank you for your answer.

    The problem with very small (close together) way borders is that you still have to click inside the boarder to move the character to the left or to the right.

    Forum Fan

    148 Posts

  • #4, by afrlmeSaturday, 25. May 2013, 03:28 11 years ago
    hmm I think you could use a mouse event listener with lua to check current y position of the character & the x position of where you click the cursor & then combine the 2 to replace the destination y position with the characters current y position & the x position where we clicked the left mouse button.

    -- let's create some variables for storing stuff in
    local char = game:getLink(VGameCurrentCharacter) -- link to current character
    local charPos = 0 -- init character position
    local curPos = 0 -- init mouse cursor position
    
    -- let's create the function for the mouseEvent listener!
    function onMouseEvent(eventType, mousePosition)
     -- on left mouse button down (pressed)
     if eventType == eEvtMouseLeftButtonDown then
     charPos = char:getPoint(VCharacterPosition).y
     curPos = getCursorPos().x
    end
    
     -- on left mouse button up (released)
     if eventType == eEvtMouseLeftButtonUp then
     char:setValue(VCharacterDestination, {x=curPos, y =charPos})
     end
    end
    
    -- let's create the mouseEvent listener
    registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp})
    


    I don't know if this is correct as I've written it straight from my noggin' to the code box here, but it should be something like - more or less!

    Long story short: we listen for left mouse button down... in which we get & store the characters y position & the cursors x position which we then use to set the new character destination on left mouse button up.

    If I'm correct then it should completely cancel out the y axis. (might be a bit of an aggressive solution though?)

    One other thing: SimonS posted a method a little while ago about controlling the character - somewhat - via key input with the arrow keys or whichever you decide to assign. http://www.visionaire-studio.net/forum/thread/keyboard-movem...

    Imperator

    7278 Posts

  • #5, by SDMonoSaturday, 25. May 2013, 03:51 11 years ago
    Thank you for your fast answer... that sounds good. I am new to Lua but I am going to try it out. Going to let you know if I get it to work. smile

    Forum Fan

    148 Posts

  • #6, by afrlmeSaturday, 25. May 2013, 06:24 11 years ago
    no worries, if you can't get it working then let me know .)

    quick note: the script type should be set to ·definition" in the script properties tab.

    P.S: there's a couple more lines that need to be added, so that the script only works when current scene is not a menu, current character is on scene & a cut-scene is not currently being executed etc.... but it's too late for me to sort it out now.

    Imperator

    7278 Posts

  • #7, by EinzelkämpferSaturday, 25. May 2013, 10:25 11 years ago
    I don't think you need scripting here. Don't forget to put way points inside your "very small" border. If you then point and click anywhere (even outside the way border) the character should walk to the way point that is nearest to the clicked position.

    Newbie

    81 Posts

  • #8, by afrlmeSaturday, 25. May 2013, 13:41 11 years ago
    I don't think you need scripting here. Don't forget to put way points inside your "very small" border. If you then point and click anywhere (even outside the way border) the character should walk to the way point that is nearest to the clicked position.


    well yeah this works too wink
    I did vaguely mention this in my first reply but didn't add the part about needing the way paths (I assumed it would be common knowledge that they needed to be added)

    As for the scripts I was offering another alternative; also which could be further adapted to restrict y axis movement & only when required.

    Imperator

    7278 Posts

  • #9, by EinzelkämpferSaturday, 25. May 2013, 17:56 11 years ago
    I'm sure your script is of good use - I can't really judge as I actually haven't read it at all... grin

    I was just referring to SDMono's second post, when he mentioned one had to click inside the "very small" border in order to move the character.

    Newbie

    81 Posts

  • #10, by SDMonoSaturday, 25. May 2013, 18:23 11 years ago
    Still messing around with the script. The problem with the way points is that then you can click wherever you want on the screen and the character will move. I dont know if it is possible to make an area no clickable. Like I said I am pretty new to all of this.

    I posted a picture on what I want to achieve.

    Forum Fan

    148 Posts

  • #11, by afrlmeSaturday, 25. May 2013, 18:32 11 years ago
    if you are doing it like that then don't add the way point paths other wise you can click outside of the borders.

    is your whole game going to be horizontal based like this?

    Imperator

    7278 Posts