RTS unit control

Hi

I’ve created a very basic RTS style camera which features zoom, mouse camera movement (based on middle mouse button being held down), also included edge scrolling (mates request, I hate it).

However I’m struggling with the unit, I’ve started with a tank, very basic features a body and a turret. My first thought would be to have the character blueprint run as an ai, that way it could attack/move on a target if they came in range. How can I get the turret to move to face the target (my trace by channel sphere) detects targets but I can’t face them, Ive followed some guides about how to find the angle between 2 vectors (very heavy maths) but because the vectors show “not in scope” I can’t see if its actually working. Well it doesn’t rotate.

Should I use the ai behave tree for this or is it easier just to have it as a standalone blueprint with an event tick checking everything.

Well, here is a complete shot-in-the-dark for your rotation. And I would use overlap events to fire it but you’ll have to do checks like if it already has a target then ignore new overlaps until it doesn’t have a target etc. I’m pretty new to the engine as well, so I hope this at least gives you something to toy with.

Hi thanks for replying.

Yeah tried that, because I’m having to get the component, it appears it doesn’t like doing said things in the ai tree. I’m currently trying it as a standalone actor. Although I never thought to do it from an overlap event, I was using a sphere trace. hmmm thanks :slight_smile:

I haven’t done a lot of work with the AI yet, but it sounds like you want to do your turret movements though a behavior tree task and your conditions under a decorator. That way it works with the tree.

Hmmm, I’ve tried your blueprint as mentioned, but mine doesn’t move at all and the cast doesn’t fail. Typically I can’t watch any of the info.

Not sure, as I mentioned, I’m pretty new to the engine myself. I’ll see if I can do a test case and let you know. Unless, someone else answers it first.

All right, I did a crude mock-up (this is the character BP). This uses the pawn-sensing component. You can just add this to the character if you want to try it that way (I found it easier to iterate than triggers directly). You will of course have to change out your component references; setting proper root locations for a turret effect was just overkill for me. This rotates the entire tank (because TankBody is passed to the transform and you’ll probaby want to go with relative once you target the turret instead).

The timeline I added which lets it rotate nicely is a single float trackthat goes from 0.0 to 3.0 over 3 seconds.

So odd, I’d created something almost exactly like that in my ai blueprint. However mine doesn’t move at a nice slow speed. Think move once and stopping. I’ve tried “rinterp to” in another blueprint which just rotates something and it still doesn’t move.

However since having a chance to sleep on the problem. I’ve realized there will be a huge performance impact if I have say 50+ tanks all tracking targets. I’m going to have a brief look into animating the turret moving. Will mean building a simple tank and very simple skeleton, but this behavior can be shared with the use of the bones anyway.

Thankyou for you help, I will update on my progress.