Download

Tank Turret Rotation Doubled

Hello. Im trying to make a tank AI and right now I have made a BT Service that check whether the player is within a certain radius. If so, the tank will move to, aim, and fire. However, I noticed that in my custom task, for some reason the turret rotation is doubled which to what I think is due to the whole tank rotating toward the player as well. You can see in the video (Link below) as I drive past the tank if the turret starts to rotate toward me but then the whole tank rotates toward me which seems to rotate the turret even more. https://streamable.com/npcx83

I think it might be because of your component hierarchy in the blueprint. Each it needs to be independent, for instance the turret should not be parented by the tank.

That’s what I was thinking because since the turret is a child of the tank it will rotate with it, however, how else could I lock it so that it stays with the tank?
Hierarchy attached

It will move with the tank anyway because they’re part of the same actor.

Tank top and cannon are correct, but take it off tankbottom.

Awesome that seems to have worked. Now This isn’t necessarily related but, now that they both rotate, is there a way to change the rotation speed?

Attached is how the tank rotates to the player

Putting this on tick should do it, but it really depends on how your components are setup:

That seemed to have helped but for some reason, the tank will rotate to me, but then randomly it will start to come at me at an angle, and other times it like snaps to my character?

Pretty tricky to sort out without knowing about the orientation of the components. What’s your code for turning the tank?

The longer one is the rotate to player. And the smaller snip is the rotate to function then the move to function.

Which tank is which here? The snippet I gave you only affects the turret and should not affect the main body…

Yea, the code you gave works. The snippet I sent above is of the AITanks main body. In the picture I sent of the game, it rotates fine for a while, then all of a sudden, it starts to move at me at an angle.

In the attached picture is the Behavior Tree. What happens is I have a service that checks to see if the player is within a certain angle of the forward vector of the aitank. If so, I do a ray cast and check to make sure that what its hitting is the player and not a wall or something. If that all works, it sets a variable to combat which starts a task that rotates/moves the tank to the player as seen in the above snippet. However, I have noticed, that when I get out of the tanks cone of vision, it sets the variable to idle just fine, but in the BT it still stays in the combat selector. Thats where I think the problem is.

That sounds likely…

Hm. I have no idea though. I have set the combat selector to abort lower priority so I dont know if that may be the reason to why it doesnt switch to the idle selector that has the wait node?

Sorry, i know nothing about BTs…

No problem. Ill probably have to make a new forum with a bt tag. Thanks for the help though.