I am making a top-down tank shooter game. The tank I’m controlling is a pawn and has 2 parts(meshes) a base and a turret. I already have the turret aiming at where my cursor is but can’t get my base to rotate to where i’m moving the tank using WASD keys. Any help would be greatly appreciated
Since we have a pawn, we have a controller - I’d opt for controller rotation:
There’s probably a dozen ways to do it, though - all depends on the juicy details.
Drag and drop the base of your tank into the blueprint and then drag out the pin from it. Get actor transform get relative or world transform, then split the pin up and rotate it from there. Once the calc is done like let’s say get rotation x + 10 make sure that you check if it goes over 359 degrees or under 0 degrees and adjust accordingly.
But I have no idea how you’re doing things so it’s a shot in the dark lol
This is how I have my movement set up. i don’t need the tank to rotate like a real tank, just need the mesh to face whichever direction the tank is going. It moves like a car basically
This is how it moves now Tank movement NO GOOD - YouTube
This is how i want it to move Toy Tanks - Top down tank shooter - Unreal Engine - YouTube
Are you 100% sure the turning in the 2nd vid is with keyboard? This is most likely done with an analog controller. Or some really fancy vector accumulation. Hard to tell from the vid.
Did you try the simple method I posted? Add Controller Yaw Input
is generally the way to go, no matter if you’re using a keyboard or a controller.
But here’s the question: do you want to turn the tank manually, or do you want the tank to turn in the direction you’re heading. These are two different things.
Also world direction is normalised. So you can put 1 there instead of 90.
IMO what I would do and I’m no pro game dev by any means… But what I would do is I would have “on event tick” check to see if you’re holding down a rotation key (bool) if true, then go to custom action “rotate tank”. So Event tick → delay (connect time to event tick) and then → branch from bool isRotatingHold? if true → custom action “Rotate tank”.
So when you do button hold then toggle the bool to true. when button is not held, toggle it to false. This is important.
Rotate tank custom event:
Drag and drop the body of the tank itself onto the BP. then get relative transform rotation. You could even do the whole movement here if you like by doing transform position. But for now, relative transform rotation, and then rotate it by x degrees you want per event tick. Make the rotation as a variable that you can edit whenever so if you want to speed up the game etc… you can do that. Then set new transformation to what you created. Make sure you join the old connections to it because you’ll reset its rotation in different axis and all that if you don’t.
Does this make sense so far?
- Don’t do Tick + delay…
- Input Axis Value already tells you if player is pressing a button.
I am not sure but yeah it’s most likely a controller. However I am totally fine with having only 8-axis rotation thats possible with a keyboard.
Yeah I tried your method, it doesn’t do anything unfortunately
I want the tank to turn in the direction I’m heading
Why not do tick + delay? AFAIK when you do this it checks the delta in the actual time vs the cycles to sync the FPS? I’ve seen this many times in tutorials although they could have been wrong.
Agreed about input axis, I was under the impression OP was using just a keyboard.
Also OP, you need to make sure you are setting the rotation back to the tank part after you add to its rotation. Drag out the node before you save the new rotation and do print string and print out the new rotation. It’s possible you also are dragging the wrong axis.
If you enable the gravity on the static mesh, you’ll get some interesting behaviours, too. The floating pawn movement provides extra control over the basic characteristics of the movement behaviour. Do explore!
Why not do tick + delay? ? I’ve seen this many times in tutorials although they could have been wrong.
That’s my biggest gripe with tutorials Why flood the latent system with unnecessary calls every frame? Also, hard to debug. If you want to tick slower:
I know you may want to wait for a frame every now and then (widget Force Prepass!) But wait for every frame?
Just to add a little:
Not the cleanest but should give you an idea if you want to body to point where the actor is moving.
This is almost perfect, but works much better in 3rd person view than top down fixed camera view.
Thanks a lot anyway though!
Movement Component is the Flight Component that comes with DefaultPawn class. (idk what class you used, but you must have a movement component regardless).
Velocity is a vector that can be split into direction where is the actor moving and magnitude (speed). I turned the direction into a rotation and set it to the tank body so it will point in the direction the actor is moving.
The Relatie Rotation is the current relative rotation of the static mesh component (TankBody).
You absolute legend. Thanks a lot!