Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fratello Manu on Tue 16/02/2021 11:38:56

Title: Characters overlapping
Post by: fratello Manu on Tue 16/02/2021 11:38:56
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) Select
  if(AreThingsOverlapping(player.ID, cNpc.ID)==true)
  {
    player.StopMoving();
  }


...but nothing changes.

Is there a way to do this?

Thanks!
Title: Re: Characters overlapping
Post by: 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 (https://adventuregamestudio.github.io/ags-manual/RepExec.html)?
Title: Re: Characters overlapping
Post by: 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.
Title: Re: Characters overlapping
Post by: fratello Manu on Tue 16/02/2021 14:03:40
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 (https://adventuregamestudio.github.io/ags-manual/RepExec.html)?

Hi, I put it into the repeat function of the room (for testing). Then I'll put it in the repeatedly_execute_always
Title: Re: Characters overlapping
Post by: fratello Manu on Tue 16/02/2021 14:12:32
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
Title: Re: Characters overlapping
Post by: arj0n on Tue 16/02/2021 15:57:48
You might want to check: Character.Solid (https://adventuregamestudio.github.io/ags-manual/Character.html?highlight=Solid#charactersolid)
Title: Re: Characters overlapping
Post by: Cassiebsg on Tue 16/02/2021 17:25:32
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.
Title: Re: Characters overlapping
Post by: fratello Manu on Tue 23/02/2021 14:12:10
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!

Title: Re: Characters overlapping
Post by: eri0o on Tue 23/02/2021 18:34:35
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
Title: Re: Characters overlapping
Post by: fratello Manu on Wed 24/02/2021 08:12:50
Hi,

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

(https://lh3.googleusercontent.com/7uXtAVZ5KDNFWuyUNgg-BPEXO1pP0N3iNc-dYYBmVYHD27QfSRLvq9dDsl7v1W21cv57jtUd4sRwrNN4636A_PZMDp2Mgzg9HYIFfyAWY1Jx-hxVJu7iBURMgPAYZQ7MKjXFZicYl6rBK_Fm8ofSW1vVsAdiLtPXMMioAm4aWdQzFdNinZLo0UQ_bSPFRQHT6YUc7eH8vnZCi3KzsJiR3huphW2FKCfKcubwS4Vl79T7Jkk0tJrUXfAsYbue1pWSFS4921BgTJ4ZjK8FsxYmez7vMwiICPcRf4jYQygexIHySxIk4rDl9vBeVGGoRpxlshh-0G2hdddrMAnxlkKmrXmzq7PG37ugzEOhfxu9MBui4vckxkGFbVcx7h5SlcNbpyK-pf5Yfv7Xb80B84oPkSY-wtywTODeVu88ZNdHXI6tqhCqu5gvtLqh6xo-dS6i1qNUR-R9hkWhru0LYxZzoQHnjBsI0glL99dzX8uqwYjQCLgIFFCLNhhh_9bzpbwsgjpnUXZXoyfpeK1otYsp169ryPR38DsuGsZq_62eXN6dDCMn2inDSINSG1z9YLvOD8uM27qaXIB2dqYuQDBFqYrEeXrLMWelgpPwP6nobP7KUTKy141Ayd_2cygzftTXMbWqsRa3hxeHKTIewCOaKWfr1tWjlDynLwD58px9tl7J0wLbIpeo9KaUJj5vOw=w389-h544-no?authuser=0)

(https://lh3.googleusercontent.com/Dtbbe-ar_RTC5uM4QG7G6epB1g10jL4vnmKWv8yGUKiUqYAnOXTtWPuO0N_wR_V9Csgls-KetbcSrUPL3_tJUZSjBExhLk6tSXMX7fh-WCKK-utm1OWmz5d8hlPIRD85F_y5ncfREumurOrkh2tY4sCv7gN2Wky96gy08wPdggfd4jImJwwRz-EhL1NhYk0XyQA2ry-f69iT-2turBbUZw9bluzCzwODA_Shz_1JQq31V0iJ090Vu5chMG9zTH7lF0rqbD3LzrQCzqvZ15DbaPkNVNdPcHoAUFjBEl3hzF7kOEsVmHMA22EIBdW2KCKX-V3Ozp-S9TgDL6-oBav_b97xvzumPHTqdPXTMaTZrfPnoKsBjdIMYIsodjJD-CpUz3RwAR-LR3FACoOfz1n9fSJiETG_eCgdFozuTTyYuBhKiJNIn7KHLlWc5sCEVwvJ-oHUzLA5ldyA_fFmWnqwKqQDJQOTFimke-_Vu48VA2vEnXPhJQETXfpWAUhjhC6W-JaOmUV8Qs-h_ICg9-q2s_X5Z8vmRLGBxNiwG_P_qWueElEQOQ-SP4uDIN7qt1NcAxZWcL1pATDlGqxjp-tSIGPXgENeSfpFMJp3buwNwBmCm55-ZRFZZRyNonmfsev_eiiFhwW00kvqwa70HY4HNNDMYJGApJrA4tOCcNR_lkTz6jW6JueDtvzGLTtAog=w359-h517-no?authuser=0)

the character has a small rectangle not-walkable area.

thanks!
bye
Title: Re: Characters overlapping
Post by: eri0o on Wed 24/02/2021 11:35:23
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.
Title: Re: Characters overlapping
Post by: Crimson Wizard on Wed 24/02/2021 12:17:08
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 :(
Title: Re: Characters overlapping
Post by: fratello Manu 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

Title: Re: Characters overlapping
Post by: Cassiebsg on Wed 24/02/2021 19:02:30
try using the collide check instead of overlapping.
Title: Re: Characters overlapping
Post by: Khris on Wed 24/02/2021 20:46:11
How did you set up the keyboard movement? Also, I can't see those screenshots, please upload them to https://imgur.com or similar.
Title: Re: Characters overlapping
Post by: eri0o on Thu 25/02/2021 00:29:30
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.
Title: Re: Characters overlapping
Post by: fratello Manu on Thu 25/02/2021 08:58:40
Nice!  :cheesy:  (laugh)