unreal-engine4unreal-blueprintunreal-engine5unreal-development-kit

The turret of tank can not be turn towards the player pawn? where is the problem?


I have a simple game done using unreal engine 4, The turret of the tank should turn toward the player pawn. I made the blueprints code to build that, but the turret rotates quickly and incorrectly. enter image description here

enter image description here

Animation of skeleton tank(2)

Animation of skeleton tank(3)

Video about problem

I tried to solve the problem many times without any results !! Hope to help me.


Solution

  • There are probably a few ways you can do this, but you can simplify this quite a bit. I also suspect you can do all of it in the animation blueprint.

    1. Simplify the first part (XDoMa.jpg) using the Find Look At Rotation node.
    2. Break the output of this and create another rotator with the yaw from that node and the pitch and roll from the turret's world rotation (you're currently setting pitch and roll to zero in cDJ08.jpg, which you don't want to do in case the tank is on a slope).
    3. To rotate the turret to point at the target, use the RInterp To node and connect its output rotator to a Set World Rotation node. The nice thing about the 'RInterp To' node is that you can set the speed. For a bit more realism you could use some simple maths to accelerate and decelerate the turret's rotation.
    4. Another thing you'll want is a bool variable in the tank actor BP. Then you can use a branch in the animation BP to trigger the stuff above when you set the bool to true.

    The key parts to this are the Find Look At Rotation and RInterp To nodes, and to do all of it in the animation BP.