Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

The problem is that there are many types of enemy soldier AI, and depending on the game’s structure and setting, they’ll function in one way or another. A soldier from *DOOM* (1993) or the first *Medal of Honor* isn’t the same as a soldier from *Call of Duty* or *Arma 3*. Even within the same game, you can have soldiers that behave differently. For example: in the first *Half-Life*, you have the marines and the Black Ops.

As I said, I’m not promising anything, but if you’re working on a game, I can try to help you create a soldier-type enemy. I’ll need at least an idea of how you expect them to function. Think of them more like a state machine or something like that, where depending on certain conditions being met, internal functions are activated or not. In other words, something like, “If I don’t see the enemy, then I patrol,” and things like that. Do you have something designed or more or less in mind?

technically, when the enemy soldiers see the player they move to a random waypoint in that area and start firing at player, when the player runs, they chase after him, i want to play hit animations when they are hit 2, preferably 2 random hit anims, but they shouldnt always play hit anims when hit, it should be probability, when they are hit, they don't attack, but after playing hit animation, they continue attacking, if you need other info you can ask please ? :)

(1 edit)

Well, the good news is that what you want isn't rocket science. Now, that doesn't make it easy.

Warning: Wall of nerdy text below. XD

Let's see, you're going to need a few extra things. To start, you need the NPC to be able to see the player. I don't know if you have anything set up for that.

If you don't have a vision system, a fairly simple way to do it is by combining a billboard with the 'near something' behavior (or whatever it's called; I have Coppercube in Spanish) that reacts to the player entering. Make that billboard a child of the NPC's mesh. When the player enters the billboard's area, send a raycast from the NPC to the player.

Why like this? The billboard's area is to detect if the player is within the NPC's field of view, and the raycast is to ensure that the player isn't behind an object like a wall.

From here: if the player is visible (within the billboard area and within raycast range), you'd need to choose a waypoint to send the NPC to. I wouldn't recommend a random waypoint because: A) the NPC could move to the other side of the map, or B) the NPC could choose the waypoint where the player is. If possible, I recommend using waypoints with names like 'cover1', 'cover2', and so on,

placed in corners or behind objects like low walls or boxes. This way, you can loop through these 'cover' waypoints and calculate the distance to find the closest one to the NPC and send them there using 'NPC pathfinding'.

Then, when the player moves out of view (beyond the billboard box mentioned earlier), you can calculate the distance between the player and all the waypoints to find the closest one. Once you have it, send any enemies currently fighting to that waypoint. If they see the player again, everything will repeat; otherwise, they'll wait for the player to appear. If you want them to keep chasing the player, you'll need to loop the distance calculation between waypoints and the player.

For the hit animations, Coppercube uses the 'AI actor' component by default, which I use in the 'NPC Pathfinding' to make Greta move from one point to another in the game. This same behavior has slots with names like 'ActionActivate' and 'ActionWhenHit'. What I suggest you try is having two behaviors for the NPC. The 'AI Game Actor' and a 'Do every x time' statement: In the first, we'll detect, for example, if the player has shot the NPC and change the value of a variable, IDK let's call it: 'NPC_state', to, say, 2. Then, in the 'Do every x time' statement, we'll check if 'NPC_state' is 2, and if so, generate a random number, for example, from 1 to 3. If it's 1, we'll play the 'Wounded' animation.

The system could be something like this: Each soldier NPC would have its own 'NPC_state' defining its current state. 0 could be 'idle' or 'waiting', 1 'attacking' (when it has spotted the player), 2 'taking damage', and 3 'dead'. In the 'AI Game Actor' statement or the the billboard, you change the NPC's state.

And with the 'Do every x time' statement, you compare the states and activate their corresponding consequences within the game.

There are forums on the Coppercube website where you could get extra help; I don't know if you've checked them out, by the way. Do you know how to program? You don't need to be an expert. I just need to know how I can best help you.

(1 edit)

Thanks for the helpful info, no, i don't program, lol, but i can try out the non-code way

You don't program like, at all? Well. A NPC like this one may become either too tricky or cumbersome to make without programming. So if you need help. I can try to create some small actions for you if you need.

Don't be afraid to ask me anything else you need.

Lucks. :-)

Oh thats very nice of you, so ummm do you know what to create or you are waiting for me? :)

Well, i have some idea of what type of soldier you wanna create. If ididn't understood wrong, you basically want to create an AI similar to DOOM from 1993. But how that AI is made and works will depend of how you are making your game. There is not a 'universal' AI that works in al games (at least not drag and drop).I am not an expert but. I can try to give you a hand. Can you share something about the game you are creating?  Not plot or lore if not' needed, but in design. How the enemies should  behave exactly?  Are you expecting to use the NPC pathfinding from this game? should the enemies 'hear' the player? are the levels linear like... Max Payne 1 or semi open like DOOM or Duke Nukem 3D? I can try to pinpoint some directions or if you want a piece of code  transformed in an action/behaviour script i can try to make it for you.

Sure, it's a linear game like Max Payne etc, i want enemies to hear player just like you said, i want them to take cover by moving to a waypoint, so for example when player enters and shoots, some of them should take cover at a waypoint node, while others directly fire, when player decides to just run away, i want enemies to not lose the player by running into  unnecessay walls, they should follow pathnodes in respect  to where player went, and attack them, similar to how the characters move to certain pathnodes in your Coppersons.ccb, I would like the code if it wouldn't be a burden to you :)

Yeah, and no. The thing is, it's not a matter of burden. Even using AI like chatGPT, a system like the one you're describing takes months to build. In the best-case scenario, it could take two months (and I'd be being extremely optimistic with that number). You don't want a simple script, but a more complete system. :-/ I can try to guide you, or as I said, by writing small, specific pieces of code, like generating random numbers or calculating distances. Now, if you're looking for me to build the entire system for you, well, not for free, sorry.

Can I suggest you make the enemies more limited? For example, I might make an action/shooter game in Coppercube in the future, but I was thinking of making the enemies stay in position (not move) and always facing the direction the playable character has to pass, as if 'waiting' for them.

Making video-games is like making illusions, you don't need to create smart NPC's, but make them look smart. :-) 

i believe so, no need to worry about making the screipt then, its not much of a necessity though, Sven (i dont know if you know him CopperCube AI (take cover) by 5v3n) has done something similar, only problem is that the enemies have snappy rotations from one path node to another, and i think they only attack a TPS Actor he made, if they were smoother , it would be better :)

but yeah,you are right, creating the illusion too might help!

looking forward to your shooting game 😁