[WORKAROUND FOUND] issues making two characters walk simulatneously

Started by Monsieur OUXX, Sat 23/05/2015 23:45:26

Previous topic - Next topic

Monsieur OUXX

Hi, I'm making this game using 3.3.0 RC1: https://drive.google.com/file/ Link removed. Contact me if you're curious and want to investigate the real cause.
(please don't download this file unless you want to help, or you'll spoil the game for yourself)

I'm having an issue for months that I can't seem to be able to fix.

Here's the protocol to replicate :
1) start the game
2) click on the "catch rabbit" button on the welcome screen
3) Change cursor to "interact" (hand icon) and click on one of the purple rabbits that wander around the main character
4) Dennis will talk and then run after the rabbit
5) ISSUE: The characters don't walk simultaneously. Whatever I try, the first one walks, THEN he stops and the other character walks.

The code to this is in function "CatchRabbit". The function is a big "if" but the part you're looking for is in code block "else if (R05_CatchRabbitCount ==2)".
As you can see the code is very messy because I've tried many things. I've even tried swapping the rabbit character ("r") with another dummy character ("dummyRabbit") just to be sure there's no other script interfering. But to no avail.

Help, please.

 

Gurok

#1
I don't know exactly why it's happening, but I suspect the blocking rectangle around characters might matter to a Walk(,,,eAnywhere) command for some reason. I actually don't know because that would mean the invisible rabbit would block things too :|. Anyway, I was able to fix it by changing:

Code: ags
cDummyRabbit.ChangeRoom(5, r.x, r.y);


to:

Code: ags
cDummyRabbit.ChangeRoom(5, r.x, r.y + 4);


Here's my complete set of changes:

Code: ags
    //swapping real rabbit with dummy rabbit(I'm having issues with 
    //making the rabbit do a non-blocking walk, probably because of a conflict
    // with the "wandering character" module
    r.Transparency = 100;
    cDummyRabbit.ChangeRoom(5, r.x, r.y + 4);
    Wait(1);
    Character* rab = r;
    r = cDummyRabbit;
    
    //speeding up rabbit and dennis
    int originalSpeed = r.WalkSpeedX;
    r.SetWalkSpeed(r.WalkSpeedX*4, r.WalkSpeedY);
    int originalSpeed2 = player.WalkSpeedX;
    player.SetWalkSpeed(player.WalkSpeedX*2, player.WalkSpeedY);
    
    //make the rabbit run and Dennis follow it
    r.Walk(r.x - 200, r.y, eNoBlock, eAnywhere);
    //Wait(1);
    //player.FollowCharacter(r, 50, 20);
    player.Walk(player.x-200,  player.y,  eNoBlock, eAnywhere);
    while (r.Moving || player.Moving) { Wait(1); }


If you shift the dummy rabbit down by a number of pixels, you should be able to compensate with the .z property. Hope this helps. I might check the engine source at some point and find out if the assumption I'm making is true. Until then, it's just my guess. Maybe someone else will chime in with a better answer :/
[img]http://7d4iqnx.gif;rWRLUuw.gi

Monsieur OUXX

Thank you so much!
How do collisions between characters work? (what's the bounding) I've noticed that characters block each other for the first time in this game (it's the first time I have NPC's walking around). I'll look into that.
 

Gurok

I don't know. It seems to not work for me more often than it works for me :/. By default, the blocking rectangle is the character's width and 5 pixels high. You can change it via Character.BlockingWidth and Character.BlockingHeight. IIRC, you can see blocking rectangles cut out of the walkable areas if you show walkable areas with the debug command. Again, I could be misdiagnosing this. I managed to get them to do some funky stuff on the same y-position when I set Dennis' Wait() delay to ~20. Stuff like, the rabbit would run, Dennis would catch him, then the rabbit would start running again.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Monsieur OUXX

You totally nailed it. My script works much better if I move my character even further right (the sprite is actually much larger than it seems, because of the sword) and if I increase the difference between the rabit speed and the character speed.
I had no idea about BlockingHeight/Width. I'll use the shit out of that -- that will also avoid collision with the other rabbits.
 

SMF spam blocked by CleanTalk