Hello, I am making a small RTS game and am struggling to figure out how to get the instances of units owned by different players to read as enemies. Currently when I have it hardcoded so it works fine (so enemy units are in a different object group). But I want to get it done through events and object variables instead so I can make different units without having to duplicate it to each players force.
What is the expected result
A player’s units recognize that instances owned by another player are “enemies” and can be targeted.
gave each Unit a UID on creation (simple incremental ID: 0,1,3,4,5,…)
in a ‚for each Unit‘ loop I added local variables that I need, when dynamically swapping between the currently handled unit and target-unit
inside the loop I can access all units by using ‚pick all‘ and access their variables&properties. use the local variables to still use the needed variables&properties from my original unit
Local variables are perfect for this, because they are not tied to an object. So you dissmiss picking issues from the same object group. Pick all gives you still access to other units from the same group while u simply use the local variables to access data that of any object that you can’t pick inside an event.
(So here I use tempX tempY to compare the handled units xy to any unit that is near. Then I save the nearest units xy inside those variables. So the tempXY served as the handled units position and then became the handled units target, to create a move command)