Search code examples
unreal-engine4unreal-blueprint

UE4 bullet controll


I'm trying to construct bullet blueprint. It's a possesed pawn projectile with initial speed set. I'd like the camera to be always set behind the bullet and it needs to be turned in direction of movement. I'd like to influence the direction it's moving with buttons W, A, S and D. I tryed for couple of hours but I'm still learning how to use UE4 and have no idea how to do this.


Solution

  • Add a spring arm component to the bullet pawn, and attach a camera to that, the spring arm will automatically follow the bullet mesh (for an even simpler setup you could skip the arm entirely and have the camera component locally offset from the mesh). If you wanted more camera control that takes a bit more work but is still fairly easy.

    Regarding rotation control, I made a fully working prototype for you (see the screenshots)

    Forward movement - Rotation control

    In this example, I use the MoveForward (W/S) and MoveRight (A/D) InputAxis event nodes to set Pitch and Yaw values (floats), multiply those values before setting them to control how fast the pawn turns (I used x50). Take the two floats and combine them into a rotator, then multiply that rotator with delta seconds (from tick) to make the rotation rate consistent regardless of framerate. Lastly, use that rotator on an AddWorldRotation node (targeting the mesh component), and run that node every tick. I used a floating pawn movement component for testing, and the mesh is set to simulate physics (mass-dependent). That being said, the same principle can be used in different ways to control rotation/angle. I'm more used to C++ but I hope this was helpful. Good luck.