Hello!
I’ve come to a bit of a road block concerning the building system in my strategy game as depicted below:
I should mention that I do still want players to be able to walk through objects within the “Buildings” object group that have the “Trap” boolean set to true.
Here is how the code is set up, courtesy of help from the Discord:
Thanks in advance!
How is the player object being moved? Through keys, mouse or something? Does the player click on one of the Movement blocks or is that just a visual?
The player clicks on the movement blocks. I should’ve been more specific, sorry lol.
Sorry, I should’ve said that I wanted a way to specifically delete movement blocks if they are behind a wall.
You can either check the locations before creating them using point is inside or a raycast or add all, of them and then check for collisions between the block and a group that just contains the non-passable objects then delete the objects in collision. If you’re using the same object for passable and non-passable or it changes over time then you could check a boolean before the collision and then delete the movement blocks that remain after the collision condition.
Can the player reach blocks on the other side of an obstacle if it’s within their reach or can they only move in straight 4 directions per move? If they can only move in straight paths then raycast might be better. It could be interesting to plan a path around obstacles. The pathfinder behavior could help do that. Unless, you want to keep it to non-blocked spaces directly in the 4 directions.
I did think of a raycast, just the problem is that bases get really big, and with all those multiplayer objects shooting raycasts at once, I think the performance would take I massive hit.
Oh, and yes, they can only move in a straight path.
How many players are there going to be? The raycast would come from the player outwards just once per move.
I played around with the concept using point is inside. I like this. It uses 2 loop counters with repeats. The 1st is for the angle. The 2nd adds the blocks. I put everything on a grid.
The events. I used a button for testing.
Raycast might be better but I wasn’t in the mood to play with both. It would be a raycast in each direction and then repeat the number of times using the number of blocks from the player to the result of the raycast. Something like
Repeat Player.DistanceToPosition(X, Y)/GridSize times
I’m marking this as the solution because for most people it is, but I’m a little hesitant to revamp my system of spawning in movement blocks as it is, as there’s several parts of the game that depends on the system being programmed in the way it is. Do you see anyway at all where I can keep my current system, while adding the ability for it to prevent players from walking through walls? Your system has given me a vague idea…
Your version is similar to mine except mine uses fewer events to make it more dynamic instead of fixed. Maybe not exactly dynamic, but it reuses events to reduce them.
You could use your method but you would need to check for obstacles using point is inside or a raycast. You would need to test each direction. Or find the distance with the raycast and repeat the needed number of times.
Since you don’t want the player to move around obstacles then my earlier collision concept wouldn’t work. At least not on its own.
Yeah, I think I’ve found a way to adapt your system to mine. I’ll keep you posted.
IT WORKS!!! Thank you so much! I couldn’t have done it without you. I’ll be adding you to the credits!