Simplified way to define enemies and allies + enemy projectiles and allied projectiles?

Hi,

I’m at a fundamental question i was always wondering about as a beginner. At the moment I script each projectile to damage only the >big turret<, but this is tedious to do for a variety of characters.

I don’t want to damage only that big turret, but anything that has an “enemy” tag or “enemy” class.

I imagine casting to “enemy” class and there are pawns, character, turrets, vehicles in it and they will be hit equally and counted down in the “health” float.

I assume there is an explanation out there, but i’m just not getting to it. Could anyone help me out and either link or explain a bit about this?

Exactly something of this sort. Thanks!

I believe nodes are called “Actor has Tag” and “get class” and then use equal or not equal, whichever one you prefer. No problem. :slight_smile: Hope you get it to work they way you envisioned.

Worked great!

This turret now turns and spawns projectiles to this enemy tag.

The class is Static Mesh Actor. (Ideally, they could be “Enemies”). The last thing:it should turn at the closest enemy. I tried every “possible” combination with line trace and a distance float, but i don’t know how to branch it or make it a criteria. Any idea about this one? Then the turret would be pretty much autonomous. :slight_smile:

It’s been a while since I touched Unreal Engine, but I came up with this. This will just get you the distance to the closest enemy w/ class and set it as new target. From there you should be able to rotate the turret towards the enemy and shoot.
I haven’t tested it with actual shooting and rotating, but when I move cubes (I have 3) it always gives me the expected result.

Shooting and rotation is in Tick. Can I plug this whole thing into Tick?

Should I connect the GetActorLocations into the “Next Target” variable? (previously in Array Element)

It’s always hard to see the big picture without looking at the code. Generally I wouldn’t use tick but just to see if it works you can do it and then maybe set up a timer or a code that runes in circle (say once every 0.5/1 second), just not every single frame.

Above code it was just an example how to get distance to closest target and set that target as variable. You probably need to do some more checks, depends on how your game is suppose to work, for example that distance isn’t a crazy value that can make game unstable. You can get Next Target variable, get actor location in the world so you can rotate towards it and shoot. But this will only get more and more complicated, I would imagine you want to finish off the target you started shooting at first, so you would need a condition for that too. It’s all nice a breezy with one turret but if you add a number of them (say 20) I would expect some fun things to happen. It will probably destroy your performance too.

My advice would be, do some pseudo coding first. Open a notepad and list all the things you want to do, how they should happen (what check you need to perform), in what order etc. This will give you immediate image of the work load and possible wall you gonna hit along the way, if you have an rough idea how to solve problem, write it down too. Don’t be afraid to recycle the code, don’t delete anything, just create a new blueprint. That way you can look at your previous approach. Try to keep things a simple as possible, use comments (white bubbles) or you will loose track of what’s going on pretty fast. Use print strings, to see the values you’re getting are what you have expected.

Thanks, I will try to keep these tips in mind! The game is very lightweight so far and I can place a ton of these turrets around the landscape. I turned dynamic shadows and everything off, aswell as in the projectiles.

…and i think the turret looks cool, too! (I even made it recoil)

(The turret shoots a projectile every 2 seconds when idle and can be controlled manually. :slight_smile: )

Can’t see the gif, upload it somewhere else eg imagur. I will have a go a this tonight, had a few ideas come to me earlier today and I want to see if I can make it work.
I’m converting the comment to an answer so it may be easier for other to find. If you think any information here can be useful to others, please accept it. Happy Coding :slight_smile:

Hi,
You can check the tag or class of the actor you hit and if it’s the one you want you apply damage if not, you just destroy the projectile (if not scripted elsewhere).

Strange, my server is pretty fast… here’s a video for multiple turrets:


Looking forward for your update!