Intelligent Keyboard Movement?

Started by MusicallyInspired, Fri 14/08/2009 21:09:03

Previous topic - Next topic

MusicallyInspired

Does there exist a script or is it possible to create a script for an intelligent keyboard movement? Specifically for pressing. But rather than a simple walk-stop-at-wall movement, is it possible for the movement to be smart enough to sense a pathway going up or down (for instance if you're walking left or right) and walk along the walkable path area instead of going straight left or right. Am I making any sense?
Buy Mage's Initiation OST (Bandcamp)
Buy Mage's Initiation (Steam, GOG, Humble)

skuttleman

The easiest way I can think of would probably be to put something like this in the on_key_press function:

Code: ags

if (keycode == eKeyLeftArrow) player.Walk(0, player.y);
else if (keycode == eKeyRightArrow) player.Walk(Room.Width, player.y);
else if (keycode == eKeyUpArrow) player.Walk(player.x, 0);
else if (keycode == eKeyDownArrow) player.Walk(player.x, Room.Height);

MusicallyInspired

Buy Mage's Initiation OST (Bandcamp)
Buy Mage's Initiation (Steam, GOG, Humble)

monkey0506

The path-finder in AGS should attempt to move the player as close as possible toward the specified point, so it should already perform as close to the "intelligent" movement as you're likely to get (at a reasonable speed). skuttleman's code should work well enough for you. ;)

Khris

#4
Isn't that code just a really short, non-working version of the Keyboard Movement module Musically Inspired was referring to...? :=

You wanna use the character's .z property.
Say you have a small bridge over a river. Now, instead of drawing the bridge's walkable area as usual, draw it flat on the river's surface (imagine the bridge's shadow at noon).
Then use formulas in rep_ex to set .z depending on the character's position.

Here's a small example game: DOWNLOAD
(Look at the walkable areas and the room script.)

EDIT: Apologies, I just got out of bed when I wrote that...
I didn't catch you were using .Walk instead of .WalkStraight.
Sorry again, skuttleman.

skuttleman

Quote from: KhrisMUC on Sat 15/08/2009 09:31:45
Isn't that code just a really short, non-working version of the Keyboard Movement module Musically Inspired was referring to...? :=

I think the Keyboard Movement module moves the player in a straight line as opposed to simulating a mouse click in a given direction from the players position. At least, that's what I understood the problem to be.

Did it do what you wanted?

MusicallyInspired

#6
I'm not sure where to put it. I want to integrate it into the Keyboard Pressing mode not the Tapping mode. The on_key_press function seems to be for the Tapping mode according to what I'm looking at here...

EDIT: I tried putting it at the end of the on_key_press function and it didn't do anything different.
Buy Mage's Initiation OST (Bandcamp)
Buy Mage's Initiation (Steam, GOG, Humble)

SMF spam blocked by CleanTalk