Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started 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)
-
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.
-
If it's only to check if the square is free or not, why not just have a bool like "isOccupied" for each square?
-
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.
-
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 :
'Array Contains' and store the index.
Then use 'Array Delete At' with that index.
Then store the new position in the 'currentPosition' variable.
-
I fixed it, it was just some arrows pointing in the wrong direction xD.
Thanks, guys I appreciate the help!