[SOLVED] Player Movement only Left & Right

Started by Priabudiman, Tue 07/07/2015 13:48:04

Previous topic - Next topic

Priabudiman

Ive browse the forum and noticed that the minimum walkable area size is 3px . Ive tried to follow that limit and go ahead and make sprites for U L R D movement. where U & L are the same sprites and so are R & D. and the result are still looking weird. player will move zigzagging up and down in that 3 px walk area.

what i want to know, is it possible to use L & R movement only? im intended to create a sidescroller feel to the player movement and walking straight in line without going zigzagging up & down in the 3 px walkable area. this one short game here is the perfect example of it.

Anyone can help? and thanks in advance...


Khris

#1
In GlobalScript.asc, on_mouse_click (or the module's / template's) you'll find ProcessClick(mouse.x, mouse.y, mouse.Mode).

You can catch WalkTo clicks and change them, by replacing the command with this:
Code: ags
    // no walkto click, so process as usual
    if (mouse.Mode != eModeWalkto) ProcessClick(mouse.x, mouse.y, mouse.Mode);
    else { // special walk processing
      ProcessClick(mouse.x, player.y - GetViewportY(), eModeWalkto);
    }


This will treat the walkto click as if you had clicked exactly to the left or right of the player, on the same horizontal line.

Edit: small code correction

Priabudiman

#2
Edit : Thank you for the reply Khris, It works like a charm,

So basically i only change the default processclick to

Code: ags
ProcessClick(mouse.x, player.y + GetViewportY(), eModeWalkto);


Is that the only code that matters in clicking anywhere and let the player walk to where the mouse click? i might have to put it on my note..

Khris

I just noticed that I was adding the viewport, not subtracting it. Just replace the + with a -.

When you call ProcessClick with eModeWalkto, AGS will send the player walking towards the coordinates of the click.
All we need to do is replace the mouse's y coordinate with the player's. This is the full extent of AGS's click handling (other than GUI clicks), so yes, this takes care of it for your entire game.

Subtracting GetViewportY() will turn the room coordinate player.y into the respective screen coordinate, in case the room has scrolled vertically.

Priabudiman

Got it!

Thanks again! this already make me hyped to continue working on my WIP updates (laugh)

~ Cheers!

SMF spam blocked by CleanTalk