Need help with keyboard movement code [yet again]

Started by Kinoko, Mon 04/07/2005 15:29:55

Previous topic - Next topic

Kinoko

If I'm against an edge above or below me and holding up and either left or right, nothing. No movement.

Kweepa

If you let go, does the character pop back a pixel?
After letting go of up or down and keep left or right held, presumably you can immediately move left or right.

[EDIT] I see it just went over a page - did you get my last edit about checking if you'd changed all three occurrences of GetWalkableAreaAt()?
Still waiting for Purity of the Surf II

Kinoko

I did check and change all of those.

I checked again and the character doesn't pop back a pixel if I let go (he stays in the exact same position) and if I let go of up or down but keep holding left or right, he does move left or right.


Kweepa

#23
Hmm, I know I tested that.
Let me check again.
[EDIT] I updated the code slightly in the TryDiagonalMove section (changed the round off if a wall was hit) - it might make a difference if you changed the speed of the character.
Still waiting for Purity of the Surf II

Kinoko

#24
Phew, this is like a workout.

Okay, I updated the code and it works fine, no problems, on upper edges.

On lower edges, it -sometimes- works fine, and sometimes doesn't.

I tried to figure out exactly where it was working and wasn't, but there seems to be something random about it.

If I hold down walk into a lower edge, THEN press left or right without letting go out down, it will SOMETIMES move, and sometimes stay perfectly still.

If I walk onto a lower edge, let go of all the buttons, then hold a diagonal, it will always work (at least it did so everytime I did it).

EDIT: Oh sorry! I forgot a condition. The only times it WON'T work are while I'm also holding 'run'. When I'm walking, this works 100% of the time. If I hold run, THEN I get the 'sometimes yes, sometimes no'.

EDIT: It almost seems to be happening every second time. Assuming I'm always running, and never let go of 'down' once I hit an edge... If I walk into a lower edge and hit left/right, it won't work. If I go up and then down again, then hit left or right, it will work. Go up and down again, hit left/right, it won't work. Will work, won't work.

Could it be a float putting this out and correcting itself every second time, or something like that?

Kweepa

Hmm, it could be your keyboard.
Did you try with the numeric keypad, going diagonally down? That's one less keypress. Or if you're using the numeric keypad, try the cursor keys.

I added some animation code to the block earlier in the thread.
This can go after oldDirect = Direct in rep_ex.

Code: ags

    // now animate the character
    if (Direct != DIR_STOP)
    {
      animFrame += 0.1;
      if (animFrame >= 10.0)
      {
        animFrame -= 9.0;
      }
      // change these if you only have four directions
      if (newDirect == DIR_DOWN_LEFT) player.Loop = 6;
      else if (newDirect == DIR_DOWN_RIGHT) player.Loop = 4;
      else if (newDirect == DIR_UP_LEFT) player.Loop = 7;
      else if (newDirect == DIR_UP_RIGHT) player.Loop = 5;
      else if (newDirect == DIR_LEFT) player.Loop = 1;
      else if (newDirect == DIR_RIGHT) player.Loop = 2;
      else if (newDirect == DIR_UP) player.Loop = 3;
      else if (newDirect == DIR_DOWN) player.Loop = 0;
      player.Frame = FloatToInt(animFrame);
    }
    else {
      // TODO: set the standing frame based on oldDirect
      player.Frame = 0;
    }
Still waiting for Purity of the Surf II

Kinoko

#26
I just tried it with the num pad and it -always- works with the diagonal keys. However, it works on/off when I use the down key, then left/right.

Forget what I said earlier about contnuously holding down/letting go and holding it again. It's the same either way.

As far as I can see at this stage, it works fine if I approach the edge diagonally.

However, (if running) if I go straight down into it, then try to go diagonally left or right, it only works every second time, no matter if I'm using num pad or directional keys.

I tried changing my 'run' button a couple of times but it was always the same result. I'd try it on my laptop but I don't have any way of transferring files into it yet but if the issue is still unresolved by tonight, I'll give it a go there too, see if it is just this laptop.

The fact that it works every second time though seems suspicious. If it were a keyboard problem, wouldn't it either work or not work 100% of the time?

Gilbert

I'm just too lazy to read all of this thread, but are you going to make the character walks while holding a directrional key, and able to change the direction immediately by pressing another direction key at once?
In that case it's possbly because of limitations to some keyboards, which can't detect some of the simultaneous key combinations (like mine at home), you may try changing the keys to say, the alphabets and test if that is the case.

Kweepa

I don't know about reading it all, but surely reading the last post would help :)
I think you're right though. It's particularly suspicious that it's only down then another direction. Although switching to the cursors and changing the run key would I thought have covered that.

I don't seem to have any problems here though.
What exactly do you mean by every second time? Every second time you run the game? Every second time you run into the wall? Can you describe a series of key presses and releases that will replicate the problem? For example:
press A
press NumPad2
<hit wall>
press NumPad1
<no movement> <holding A, NP2, NP1>
release NumPad1
release NumPad2
press NumPad8
release NumPad8
press NumPad2
<hit wall>
press NumPad1
<slides> <holding A, NP2, NP1>
Still waiting for Purity of the Surf II

Kinoko

I have the midfortune to announce that it happens with edges in all 4 directions. I guess when I first started it just randomly worked but when I tested just then, it's not just happening with lower edges.

I also discovered it's not just happening with moving -diagonally- left or right either.

Basically, if I run to an edge (say a left edge)  - press up - no movement - press down - no movement - press right (walk away from the edge) - press left (walk back to the edge) - ... etc

That's always running, and I tested all that while letting go of every direction key before hitting another, so at no time was I holding two at once.

Another example [assuming 'run' is always held and all these keys are let go of before the next is pushed]:

DOWN [into an edge]
LEFT
RIGHT
UP
DOWN
LEFT
RIGHT
UP
DOWN
RIGHT
UP
DOWN
LEFT
UP

...etc

It doesn't even happen every second time anymore, just completely randomly. Each time I hit an edge and then try to move along it, it may work or it may not.

Kweepa

#30
Yeah, I get that too now. Oops.
Looks like I need to check this out further.
I'll get back to you.
Did the animation code work out ok?

[EDIT] Found it. Change "round off the position" in TryStraightMove() to

Code: ags

      // round off the position
      characterX = IntToFloat(player.x) + 0.5;
      characterY = IntToFloat(player.y) + 0.5;


and move the player position set code in rep_ex inside the while loop so the end of it looks like:

Code: ags

        else if (newDirect == DIR_DOWN) {
          dist = TryStraightMove(dist, 0, 1);
        }
        player.x = FloatToInt(characterX);
        player.y = FloatToInt(characterY);
      }
    }
    oldDirect = Direct;


I will update the full code earlier in the thread to reflect this.
Seems pretty solid now.
Still waiting for Purity of the Surf II

Kinoko

It sort of works. I had to change it slightly because I don't use diagonal loops, but I got a couple of illegal exceptions when walking around.

Basically I changed it like this:
Code: ags

// now animate the character
    if (Direct != DIR_STOP)
    {
      animFrame += 0.1;
      if (animFrame >= 10.0)
      {
        animFrame -= 9.0;
      }
      // change these if you only have four directions
      if (newDirect == DIR_DOWN_LEFT) player.Loop = 0;
      else if (newDirect == DIR_DOWN_RIGHT) player.Loop = 0;
      else if (newDirect == DIR_UP_LEFT) player.Loop = 1;
      else if (newDirect == DIR_UP_RIGHT) player.Loop = 1;
      else if (newDirect == DIR_LEFT) player.Loop = 1;
      else if (newDirect == DIR_RIGHT) player.Loop = 2;
      else if (newDirect == DIR_UP) player.Loop = 3;
      else if (newDirect == DIR_DOWN) player.Loop = 0;
      player.Frame = FloatToInt(animFrame);
    }
    else {
      // TODO: set the standing frame based on oldDirect
      player.Frame = 0;
    }


It'll occasionally give me an error for lines like       else if (newDirect == DIR_LEFT) player.Loop = 1; saying the loop specified isn't right, but... I can't figure out what could be wrong with that.

Also, it doesn't walk smoothly. If I walk in a straight line for a bit, it only animates a little, stops, animates a little, stops, animates a little, stops, etc...

Plus, it animates too fast but that's easily changed, really. ^_^

Kweepa

I forgot to mention (guess I thought it was obvious :=) that you should change the 10.0 and 9.0 depend on how many frames of animation the walk animation has (I'm assuming they're all the same).
These numbers are for Roger who has 9 walk frames plus one standing still frame.

Oh, and add "animFrame = 1.0;" after "player.Frame = 0;" in the else clause, just to start the animation off from the same frame every time.
Still waiting for Purity of the Surf II

Kinoko

Ah right. It works smoothly now :)

I'm still getting occasional errors with my newdirect == lines and it still animates too fast, but much better.

Kweepa

Just to be sure we're on the same page, to slow down the animation, change "animFrame += 0.1" to say "animFrame += 0.05" to halve the speed.

I'm not sure how you'd get those errors, unless the player's view was changed. You should wait until (newDirect == DIR_STOP) to change the view, and change it back to the walking view (in rep_ex) before this animation code when (oldDirect == DIR_STOP && newDirect != DIR_STOP).

Cheers,
Steve
Still waiting for Purity of the Surf II

Kinoko

I'm a little confused, I'm not sure where in the code you're talking about.

I haven't written any code for changing the view between running and walking yet, so yeah, I have no idea why the erros are coming up.

Kweepa

Is there an idle view for the character? With just one loop?
You may have to stop the character from idling every so often since AGS isn't aware the character is moving (we're moving the character behind AGS's back).
Still waiting for Purity of the Surf II

Kinoko

Aha, that appears to be it. I did have an idle view with only one loop. I've increased it to all 4 loops now and the game didn't crash but yeah, the character did eventually start it's idle animation.

Perhaps to counter this, we could have some variable that changes to 1 when walking and have the engine check... hmm. Nope. I can't really think of a way to get the idle working properly. I could have a timer start after the character stops perhaps.

Kweepa

I'll check it out and get back to you, unless anyone else knows how to temporarily prevent idles...?
Still waiting for Purity of the Surf II

Kinoko

Perhaps just using SetIdle and passing it as -1 when walking starts and re-setting it again when the character stops.

SMF spam blocked by CleanTalk