Characters overlapping

Started by fratello Manu, Tue 16/02/2021 11:38:56

Previous topic - Next topic

fratello Manu

Hi everyone!

I need to avoid characters overlapping.
I thought it was enough to set all characters as "solid" but overlapping still occurs.

So I tried to make a function to stop characters movement (e.g. player) if "colliding" with npc's area:


Code: ags
  if(AreThingsOverlapping(player.ID, cNpc.ID)==true)
  {
    player.StopMoving();
  }


...but nothing changes.

Is there a way to do this?

Thanks!

Matti

I guess the player.Walk command is blocking? Have you tried putting that code in repeatedly_execute_always?

Khris

Can you be more specific about your setup?

Characters being solid means that they have a rectangle around their feet that cuts a hole out of the walkable areas.
AreThingsOverlapping on the other hand is a 2D test of the character's bounding rectangles.

Is this a top-down game?

Also, you can press Ctrl-A during the game to see the walkable areas.

fratello Manu

Quote from: Matti on Tue 16/02/2021 13:34:56
I guess the player.Walk command is blocking? Have you tried putting that code in repeatedly_execute_always?

Hi, I put it into the repeat function of the room (for testing). Then I'll put it in the repeatedly_execute_always

fratello Manu

Quote from: Khris on Tue 16/02/2021 13:48:28
Can you be more specific about your setup?

Characters being solid means that they have a rectangle around their feet that cuts a hole out of the walkable areas.
AreThingsOverlapping on the other hand is a 2D test of the character's bounding rectangles.

Is this a top-down game?

Also, you can press Ctrl-A during the game to see the walkable areas.

Thanks
I understand, but it doesn't seem to work. I expected the "hole" in walkable area around the character's feet, but it doesn't seem to be there at all (player can "cross" the NPC and overlap him)

I didn't catch what you mean with "top-down" game; if you mean if there's some vertical scrolling, yes, there is

bye!thanks

arj0n


Cassiebsg

You might want to share a sprite of your character and eventually a screenshoot in game showing the problem.

you also have character.z, if your characters feet ara higher up than the sprite's bottom edge.
There are those who believe that life here began out there...

fratello Manu

I made a short video to let you understand the problem.

Both characters are solid (girl and spider), but it's not working (overlapping and walking-through)

Movement is handled by arrow keys

Thanks!


eri0o

Can you print screen this exact screen with Ctrl+A? Ctrl+A should show the walkable areas including the characters cutouts (on their feet, if they are solid)

If Ctrl+A does nothing, you may need to call Debug(2,1); on a key press or some other way.

https://adventuregamestudio.github.io/ags-manual/Globalfunctions_General.html#debug

fratello Manu

Hi,

here the screenshots of the area and of the walkable areas:





the character has a small rectangle not-walkable area.

thanks!
bye

eri0o

It seems that the walkable areas used by the pathfinder in AGS are edited and cleared by the engine, so these boxes at the solid characters feet are just not there when accessing through the script API.

I can't figure out a way to get them from the script API, even just their dimensions.

So it seems the obvious way would be to give an API for you to pass the desired bouding boxes to use, and you would do this every frame, before calling controlz. As a bonus this gives... Erh... Control as to what the size of the collision box should be which can be useful - the solid box from AGS is known for being quite... Inflexible.

If this seems alright I can add.

Crimson Wizard

#11
There's Character.BlockingWidth and BlockingHeight.

It's limited to how it's aligned, but it's what exists at the moment. You may also adjust Character.z to additionally offset character image along Y axis and for example align collision to character sprite's vertical center.
(There was already a feature request to provide more flexible setup for character collision.)

If that's not enough, the solution is either to use dummy invisible characters and create blocking area with these, or script your own walking and collision. The fact that your game is kind of grid-based may make this easier a bit.


PS. I cannot see the screenshots though :(

fratello Manu

Quote from: eri0o on Wed 24/02/2021 11:35:23

So it seems the obvious way would be to give an API for you to pass the desired bouding boxes to use, and you would do this every frame, before calling controlz. As a bonus this gives... Erh... Control as to what the size of the collision box should be which can be useful - the solid box from AGS is known for being quite... Inflexible.

If this seems alright I can add.

thank everyone.

I tried setting at game start the Character.BlockingWidth and BlockingHeight for each character (e.g. 40 x 40) but nothing seems to change.
I tried enabling the mouse cursor and I confirm you that in that way all is working. So maybe the solution is in changing something in Controlz, as you suggest...

HAve a nice day


Cassiebsg

try using the collide check instead of overlapping.
There are those who believe that life here began out there...

Khris

How did you set up the keyboard movement? Also, I can't see those screenshots, please upload them to https://imgur.com or similar.

eri0o

#15
Quote from: manu_controvento on Wed 24/02/2021 14:40:37
Quote from: eri0o on Wed 24/02/2021 11:35:23

So it seems the obvious way would be to give an API for you to pass the desired bouding boxes to use, and you would do this every frame, before calling controlz. As a bonus this gives... Erh... Control as to what the size of the collision box should be which can be useful - the solid box from AGS is known for being quite... Inflexible.

If this seems alright I can add.

thank everyone.

I tried setting at game start the Character.BlockingWidth and BlockingHeight for each character (e.g. 40 x 40) but nothing seems to change.
I tried enabling the mouse cursor and I confirm you that in that way all is working. So maybe the solution is in changing something in Controlz, as you suggest...

HAve a nice day



I think I implemented alright in controlz now, please check the new version in the thread if it works for you. It will use the BlockinWidth and BlockingHeight of others, if you leave at 0 it will use the default config. In my tests it worked alright.

If you need objects please tell me.


SMF spam blocked by CleanTalk