Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: kitkat29 on July 20, 2018, 04:19:36 PM

Title: Detecting Objects [SOLVED]
Post by: kitkat29 on July 20, 2018, 04:19:36 PM
Hello,
I need some help with figuring out how to detect if an object is already inside a square. In the picture I have 2 characters, I don't want them to be able to be inside the same square. I have all of the character movement, so when you click on a character it will ask you to select a square. https://gyazo.com/be6a836ba8d559a7fdb819dc987f67de (https://gyazo.com/be6a836ba8d559a7fdb819dc987f67de)
Title: Re: Detecting Objects
Post by: djaydino on July 20, 2018, 06:07:26 PM
Hi.
There are a few ways i can think of.

For example :
Have an array called (for example) "occupied".

once a player is on a square add it to the occupied array by using 'Array Add'.

When the player selects a square, use 'Array Contains' and check with the selected square.

When a character leaves a square, use 'Array Contains' and store the index.
Then use 'Array Delete At' with that index.
Title: Re: Detecting Objects
Post by: DanielThomas on July 20, 2018, 08:14:11 PM
If it's only to check if the square is free or not, why not just have a bool like "isOccupied" for each square?
Title: Re: Detecting Objects
Post by: kitkat29 on July 20, 2018, 10:49:13 PM
So I have it working but the problem is the square is still stored in the array. When the character clicks on a new square should I have something to delete the previous square from the array if so how would I go about doing that.
Title: Re: Detecting Objects
Post by: djaydino on July 22, 2018, 02:19:11 PM
Hi,
@ start store the object where the player is in a variable (call it currentPosition for example) , then when targeting a new position and it is empty, do this :
Quote
'Array Contains' and store the index.
Then use 'Array Delete At' with that index.
Then store the new position in the 'currentPosition' variable.
Title: Fixed it
Post by: kitkat29 on July 23, 2018, 04:15:20 PM
I fixed it, it was just some arrows pointing in the wrong direction xD.

Thanks, guys I appreciate the help!