Different Walking Speeds on the X Axis

Started by ToothpasteBruva, Sat 21/05/2016 02:30:37

Previous topic - Next topic

ToothpasteBruva

Hi all,

Simple question. Is it possible to have a separate walking speed for walking left (horizontally) and walking right? If not, are there any workarounds?

Thanks

Mandle

I think you need a workaround:

I would detect if the click is left or right from the current position of the character and set walking speed respectively...

Joe

What Mandle says would work on simple rooms only. If walkable areas have a complex shape that solution wouldn't work. You would need to constantly check the character X increment and if it's positive set the 'right' speed, and if it's negative set the 'left' speed.
Copinstar © Oficial Site

Haggis

#3
This might be making it too complex - but, rather than checking x/y increments, you could do this by checking the current character loop. If it's the up/down loop number & walking view combination then set speed as required. Same for left/right.

Edit: You could effectively set a different speed for each direction.

Mandle

Quote from: Joe on Sun 22/05/2016 22:19:32
What Mandle says would work on simple rooms only.

True: I was just imagining a side-scroller kind of movement...

ToothpasteBruva

Hi all,
Sorry for the late response. I'm at work now so I'll try these out later. From what I remember when I change the walkX speed by detecting which direction the character is walking, the game stalls and says something to the effect of "Cannot change walk speed while character is walking". I'll try the check loop method tonight and get back to you.
Thanks!

Slasher

Quote"Cannot change walk speed while character is walking".

You must first use
Code: ags
Player.StopMoving();

ToothpasteBruva

Quote from: slasher on Thu 26/05/2016 05:51:50

You must first use
Code: ags
Player.StopMoving();


But Slasher that stops the character from walking. Do I need to resend the walk command? Here's what I got so far.
Code: ags

function room_RepExec()

  if (cCharacter.Loop == 2)
  {
    cCharacter.StopMoving();
    cCharacter.SetWalkSpeed(2, 4); 
  }

Slasher

as far as i am aware should a character's speed change then they need to stop first... but it's not really that noticeable...

but if the character is not moving then i can't see any reason to add stopmoving...

add to Rep Exec to check and add loop/speed conditions..






dayowlron

#9
I may be wrong but if you stop the character from moving then start them moving again they will restart the animation loop over again. If this is happening in the RepExec function then it will be doing this so you will never see beyond the second frame of the animation loop. If that is the case then you probably want to change your check to see if anything needs to be done to be something like
if (cCharacter.Loop == 2 && cCharacter.WalkSpeedX <> 2)
{
    ....
}
Also you will need to have it start walking again after you have set the walk speed so not sure how you can determine where the player wanted the character to walk to.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Slasher

Something like this?
Code: ags

if(!player.Moving) // if player is not moving
 if(player.Loop=0)
 // setwalkspeed this
else if (players.Loop=1)
 // setwalkspeed this
else if (players.Loop=2)
 // setwalkspeed this
else if (players.Loop=3)
 // setwalkspeed this


Khris

The only way I can see is storing the walk target coordinates, calling StopMoving(), changing the speed, then calling Walk() again, using the stored coordinates.

When I wrote my KeyboardMovement module I wanted to implement a run key, like holding down Shift. I ended up implementing a completely custom walk system, since there's no other solution to this problem using just Walk().

dayowlron

If you are able to find the place in the code where you will be able to store the walk target coordinates then just set the walk speed there before the walking commences and you would not need to do any of this other stuff.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Khris

dayowlron, this question is about changing the speed mid-walk. What you just posted makes no sense.

dayowlron

His original question was having different speeds for left than right. not changing it mid-walk, so unless the original question was changed mid stream it does make sense.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Slasher

#15
What Khris commented:

QuoteThe only way I can see is storing the walk target coordinates, calling StopMoving(), changing the speed, then calling Walk() again, using the stored coordinates.
That makes a lot of sense.

AFAIK a few people have managed to build their own Walk functions and stuff to allow going from Walk to Run without stopping.

I don't know why the setwalkspeed no stopping has not yet been addressed into ags...

ToothpasteBruva

Quote from: slasher on Fri 27/05/2016 18:53:05
QuoteThe only way I can see is storing the walk target coordinates, calling StopMoving(), changing the speed, then calling Walk() again, using the stored coordinates.
That makes a lot of sense

Cool that partially works, but only when I use eblock in walk. So you can't do anything until the character reaches the mouse coordinates. This is also a level where you are dodging debris on a road so the controls need to be pretty responsive. I hope this is possible. It sounds like I'm trying to do something AGS really wasn't designed for.

Mandle

Hmmmmmmm...

A possible workaround:

How about adding/subtracting some of the character's x-axis each game loop if the character is not standing still?

Put in repeatedly execute:
Code: ags

if(cEgo.moving==true)
 {
  cEgo.x=cEgo.x-2;
 }


(code untested...not sure about the exact syntax of cEgo.moving, but I think it's right)

This may make the character seem to "moonwalk" in one direction and take leaps and bounds a bit in the other, but this may also be a desired effect if the character is supposed to be walking against/blown along by the wind, which it sounds like you are trying to achieve...

Khris

Dodging debris on a road indeed sounds like something that shouldn't be implemented using Character.Walk() in the first place.

ToothpasteBruva, can you be a bit more specific about the game mechanic?

Snarky

To Mandle's solution: Clever, but somehow I don't think manipulating the character's coordinates directly while it's moving will work. Not sure whether it will crash, ignore the command, stop the walk, or cause buggy pathfinding, but I'm 99% sure something will disallow it.

Quote from: ToothpasteBruva on Sat 28/05/2016 03:48:21
Cool that partially works, but only when I use eblock in walk.

How does it not work otherwise? It's probably fixable. (I'm guessing it has to do with running the code every cycle, without properly testing for the relevant conditions.)

SMF spam blocked by CleanTalk