Hello,
I have a coin pickup that destroys itself when overlap with player pawn happens and then another coin spawns on the map on a random location from an array of target points. I want to aviod 2 coins spawning at the same target point at the same time so I want the coin itself to detect if it hit another coin and then destroy itself and spawn another one on another random location. How can I do this the most simple way?
Thanks in advance
Make a custom collision channel for the coin. Set it to overlap the player and itself. Make a custom function onOverlap that will destroy the coin and respawn the coin at your random or target locations.
Yeah I’ve got that part solved, the issue is that when the coin picks from the random target points he doesn’t know if there already is a coin at that point that spawned before. If that happens and I get 2 coins at the same location I want only one of them to destroy and respawn at another random one until he finds a free space. The problem if I attach a destroy actor on the coin both coins will register a collision with eachother and both will destroy themselves and spawn another on different locations and I only need one to do so.
You can make an array that will record the coins vector position on spawn, and remove the position on destroy. When a coin wants to spawn check to see if that vector already holds a coin, if not spawn ,if so find another random position.
Also in the spawnActor node you can utilize the collision Handling Override. Either by trying to adjust collision or not spawning. If the return value is none, a spawn failed and try again.
Hope this helps.
I already tried that but I want the coins to be able to spawn on the same place twice, if I remove the spawn from the array after spawning it eventually runs out of spawn points and forces them together and if I repopulate the array there will be a chance of them spawning in the same place again since all of them will be back for grabs. I really need to make it so that on two same coins overlap event only one executes.
The array method would work, but will take a bit more detailed explaining . So to make things as simple as possible, how about when you spawn a coin, get the overlapping actors, if a coin is part of the array (2 coins are on top of each other), destroy the spawned coin and call spawn again. The original coin will not be effected. Doing this u might want to hide coin visibility until u are certain that you are in a valid location, otherwise u might see some geo popping.