Different Walking Speeds on the X Axis

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

Previous topic - Next topic

Mandle

Quote from: Snarky on Mon 30/05/2016 09:43:07
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.

Hmmmm...In my current project I'm doing pretty much the same thing, except it's with the Move command instead of Walk, and everything is just fine so far...I can change characters' x and y coordinates directly and they continue moving in the direction they were headed before the "warp"...

I am telling the characters where to go mind you, it wasn't determined by a mouse click...

Retro Wolf

I'm under the impression that the path is calculated before the character sets off when using the walk function.
So I think screwing with the x coordinates while the character is following that path may cause issues. Not tested it myself though.

Mandle

I also just realized that even if it does work, the "faster" direction would push the character onto non-walkable areas when you hit them, so it would require a check beforehand if the coordinate is walkable/non-walkable...

In my project the characters can move anywhere so it's not an issue...

ToothpasteBruva

#23
Yes that seems to be the case. Changing the x coodinates after walk has been sent (even when using the keyboard for some reason) creates a jittering effect. Here's a screengrab just to show what's going on. The background is constantly scrolling, and it goes faster the more left you go. I want the player to be able to slow down/move right faster than when speeding up/moving left. It's not super essential, but it would be nice.
In the mean time I'll try using Move instead of walk.
http://dl.dropboxusercontent.com/s/vdpopk3qjjqpsf7/carscene.png?raw=1?


Snarky

The jittering has to do with AGS updating the positions of the viewscreen and character after the user-script runs, but before the screen is rendered each cycle. To get around that, you want to use late_repeatedly_execute_always() rather than the normal function.

ToothpasteBruva

#25
Okay I finally got this working! However I had to create my own walk controls in the end. :embarrassed: That's fine though because it means I have more flexibility such as adding ease to the car movement.
Code: ags


int varSpeedRight = 0;
int varSpeedLeft = 0;
int varxi = 0;
int varyi = 0;

  if (IsKeyPressed(eKeyRightArrow) == true && cRocketcar.x > 200 && cRocketcar.x < 600)// when -> pressed make sure the car is in the walk area
  {
    if (varSpeedRight < 10) // if car is going slower that 10px per loop
    {
      varSpeedRight = varSpeedRight + 1; // increase right speed variable
    }
    cRocketcar.x = cRocketcar.x + varSpeedRight; // add right speed variable to x location
  }
    if (IsKeyPressed(eKeyRightArrow) == false) // if -> isn't pressed
  {
    if (varSpeedRight > 0) // and right speed is above 0
    {
      varSpeedRight = varSpeedRight -1; // then subtract until it = 0
    }
    cRocketcar.x = cRocketcar.x + varSpeedRight; // subtract varrightspeed until car stops
  }
  if (IsKeyPressed(eKeyLeftArrow) == true && cRocketcar.x > 210 && cRocketcar.x <710)
  {
    cRocketcar.x = cRocketcar.x -4;
  }

//And so on for up and down. For the mouse controls

  if(mouse.IsButtonDown(eMouseLeft))
  { 
    varxi = mouse.x - cRocketcar.x; //delta x = mouse x - object x
    varyi = mouse.y - cRocketcar.y; //delta y = mouse y - object y
    
    
    if (cRocketcar.y < 300) // keeps car within walkable area
    {
      cRocketcar.y = 304;
    }
    if (cRocketcar.y > 430)
    {
      cRocketcar.y = cRocketcar.y - 2;
    }

    if (mouse.x < cRocketcar.x) // if car is moving left
     {
      cRocketcar.x = cRocketcar.x + varxi/80; //dividing delta x determines speed car moves towards mouse
     }
     else
     {
       cRocketcar.x = cRocketcar.x + varxi/20;
     }
     cRocketcar.y = cRocketcar.y + varyi/30;
     
    }


Thanks a tonne for all the help.

SMF spam blocked by CleanTalk