Where's the Cover?

It is disappointing that Code Monkey promised an X-Com-like course and didn’t bother including a Cover System. My interest was initially piqued with this video: I made XCOM in 25 HOURS! (plus Special Announcement!) - YouTube

I’ve appreciated the lectures, as he taught a lot of gems, but where’s the one fundamental when it comes to Tactics Games?

That video was the original prototype, there’s a lot of work that is required when converting a self-made prototype into a step by step course, so in that process I decided it was best to focus on a more general design rather than a XCOM specific design and in doing so I opted to instead focus on adding features like the general Interact action instead.

With the knowledge you gained from following the course you should be able to build it yourself.
For defining what is cover, you just need to have some script storing a basic enum NoCover, HalfCover, FullCover

Then for populating the cover data in the grid, you can do the exact same thing as on the Pathfinding script, cycle through all the grid positions, do a Raycast and test if the object has the cover script, if so update the Grid Object with the cover state.

Then it depends on how you want to use that data, you can query the Grid Positions around each unit to define what cover to apply to it and perhaps apply some miss percentage or less damage depending on the cover state of the target unit.

1 Like

Cool to see you reply.

I’ll bang my head against implementing that. The big thing for me is more weapon ranges (bonuses and penalties), plus different types of guns; where would you suggest I build those? i.e. make a Weapons Script that has all of the stats or divide the weapons into different Scripts: shotgun, sniper rifle, rifle, etc.

The other big thing for me is Hexes and also 3D. Like being able to climb on top of those walls and run around. But I guess I’m just a glutton for punishment.

I’m closer to realizing that than before I took the course, so thank you.

You mean calculating the hit percentage? That’s mainly just some math depending on whatever elements you want to take into account.

XCOM 2 actually shows you all the elements that go into the calculation, you can see it’s based on distance (which in this case you can either do a Vector3.Distance() or ask the Pathfinding for the Path length), then it’s based on the cover amount of the unit (so the system I mentioned previously) then there’s a bonus if it’s flanking, you can test that by doing some math between the shooter position, the target position and where the cover is (I covered some similar logic in the Backstab video Code Monkey - How to do a BACKSTAB! (Like Elden Ring, Dark Souls | Unity Tutorial) )

Then for weapons, perhaps you have just a handful of weapons (perhaps defined as Scriptable Objects Code Monkey - Make your Games Designer Friendly! (Scriptable Objects)) and each weapon has a base Aim and base Damage amount. Perhaps you have a strategy layer on top and unique units that by themselves also have a base aim amount and perhaps even upgrades on the weapons, etc, etc.

That’s just a rough outline for how I would do it but as usual there’s many many ways to implement a certain mechanic, it all depends on exactly the design you’re trying to build.

As for a hex grid, that is indeed one of the main things I’d like to cover in a future update, it’s also pretty simple since the “shape” of the grid is just math on the Grid System, very few things need to change to change the grid to hex.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms