Characters passing through each other, despite "Solid" property and function

Started by TheFlyingBlender, Wed 08/03/2017 01:02:41

Previous topic - Next topic

TheFlyingBlender

Hi friends!  I hope I did sufficient due diligence in forum/wiki/help searching, but I can't seem to figure this out.  But I'm also green as grass, so I'm sure it's something simple.

So I have my default cEgo, and a cAbby.  Both have the "Solid" property set to "True" under the Movement heading in their respective properties.  This didn't work, so I also went to the Global Script and, under the game start function, added the Character.Solid property.  It looks as follows:

function game_start()
{
   initialize_control_panel();
  KeyboardMovement.SetMode(eKeyboardMovement_Tapping);
  cEgo.Solid = true;
  cAbby.Solid = true;
}

However, cEgo will still walk right through (under) cAbby.

Thanks in advance for any thoughts you can offer! =)

Khris

You should be able to see the hole cut into the walkable areas by the NPC if you press Ctrl+A during the game.
If your game is high-res, the hole might be too small. In that case you can set the character's .BlockingWidth and .BlockingHeight to a higher value.

TheFlyingBlender

Quote from: Khris on Wed 08/03/2017 10:45:57
You should be able to see the hole cut into the walkable areas by the NPC if you press Ctrl+A during the game.

Ohh, that's super handy!  I think I'll be using that a lot.

QuoteIf your game is high-res, the hole might be too small. In that case you can set the character's .BlockingWidth and .BlockingHeight to a higher value.

I wasn't able to find the hole cAbby was making, but setting one using those properties definitely made one appear.  So problem solved! 

I find I was misunderstanding how 'collisions' are detected though.  I was assuming the hole (or collision mask) was based on the shape of the sprite with its alpha channel.  I will be having a much larger character later in the game where a more precise hole will be required - is there a way to base the hole around the sprite shape like I initially assumed it was?  Or am I going to have use the Walkable Area layer to define this (and change it each time the larger character changes views/animations)?

Otherwise, thanks very much for clearing that up for me, it worked great!

Khris

That's weird, I always thought that characters have a default blockingwidth/height. Glad you solved it though.

As for more precise blocking, you cannot easily offset the hole, unfortunately.
It's possible to let AGS draw the character's sprite further up or down using cNPC.z, independent of the drawing order and their position in the room and therefore their "hole". That way one could shift the position of the hole, but it might not work really well or cause glitches.

If you want a truly custom hole, you might have to resort to some other way of blocking. One solution is a secondary, fully transparent character/object that is moved inside repeatedly_execute_always() so it always properly blocks the WA around the NPC's feet.

Snarky

AGS assumes a traditional "third-person adventure game perspective" where the characters' feet are at the bottom of their sprites (and you're only interested in their feet colliding). If you're using something else (e.g. a top-down view or side view), or you want to check for their sprites touching at all, which it sounds like you want, you may be looking for pixel-perfect collision detection instead. There's a module for that (and alternate solutions including a plugin and a Lua script for use with AGS-Lua):

http://www.adventuregamestudio.co.uk/forums/index.php?topic=26307
http://americangirlscouts.org/agsresources/modules.html (since the original dl link is broken, get it from here)

Alternatively, if it doesn't need to be pixel-perfect, a simpler solution is to use hitboxes (which is what the built-in AGS system essentially amounts to). It's pretty easy to write your own implementation, and you can define the hitbox as a custom character property.

However (it now occurs to me after writing this post), the challenge is to integrate it with the AGS pathfinding. Khris's solution (a transparent character representing the blocking area) is probably better for that.

TheFlyingBlender

You nailed it actually Snarky, I'm trying to do a top-down perspective.  That probably would have been helpful information, sorry I didn't mention it!

I'm not sure I understand Khris' solution though.  How would a duplicate character be able to block a specific hole shape just by placing it in repeatedly_execute_always?

Is there any way to switch to alternate walkable area layers without reloading or changing rooms?

Thanks again for all your help here, I really appreciate it.

Khris

The idea was to always move the transparent character into position, like this:
Code: ags
function repeatedly_execute_always() {
  if (player.Room == cNpc.Room) {
    cNpcHole.x = cNpc.x;
    cNpcHole.y = cNpx.y - 12;
  }
}


However if this is indeed a top-down game, it's much simpler to just set cNpc.z to -20 or -30 or whatever, depending on the height of the sprite. That way the character's sprite will move down in relation to their game position and hole, allowing you to center the sprite on them.

SMF spam blocked by CleanTalk