# (tank controls) keeping forward orientation after releasing fwd button but turning

**URL:** <https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203>\
**Category:** Character & Animation\
**Tags:** turning, unreal-engine, question\
**Created:** [December 6, 2019, 3:39pm UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203 "2019-12-06T15:39:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_5f425dc7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5f425dc7](https://forums.unrealengine.com/u/anonymous_user_5f425dc7)\
**Post date:** [December 6, 2019, 3:39pm UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/1 "2019-12-06T15:39:08Z")

</div>

I have no idea how to make a short descriptive question about this. Essentially I have tank controls. W forward, S backward, a and d turn left right. With mouse look. Like world of tanks. My issue is that after I gather some speed holding w button I release the w button and then press either a or d. My character turns but keeps going straight which means it ends up sort of moonwalking sideways. How do I get the character to turn and move to that direction when neither w nor s is pressed?

Here are my movement and turning bp. Nothing fancy except long acceleration and deceleration times which are not shown here. And during those deceleration moments I’d like to steer the character with a/d buttons

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/7/d/e7d579ec3cb99eae6ce8f026d857c0ea8fba0e97.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 7, 2019, 12:03am UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/2 "2019-12-07T00:03:27Z")

</div>

For basic tank controls you could try something like this:

 ![293521-annotation-2019-12-07-000049.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/5/1/e518769a48d64d39994cef9d08594a013fec2cd0.png)

This accumulates the speed factor in a variable and then applies is constantly.

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/f/9/3f9c8e5a5da4ef0cbfadd1d3630ab4a1038ce9ce.gif)](https://gyazo.com/e450ee7a16bb81514cb24d68f4bbb616)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5f425dc7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5f425dc7](https://forums.unrealengine.com/u/anonymous_user_5f425dc7)\
**Post date:** [December 7, 2019, 7:59am UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/3 "2019-12-07T07:59:47Z")

</div>

Thanks for the response. The way I have set up my controls is that I’d need to hold w key to keep going forward. This also accelerates the character forwards until I reach max speed. Switching to speed based movement where w and s just increase and decrease the speed could be a solution but I sort of prefer the button holding because I need lots of small movements occasionally and the speed based system is a bit slow for that.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 7, 2019, 9:51am UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/4 "2019-12-07T09:51:28Z")

</div>

> Thanks for the response. The way I  
> have set up my controls is that I’d  
> need to hold w key to keep going  
> forward. This also accelerates the  
> character forwards until I reach max  
> speed.

Makes sense.

It’s a bit unclear to me how the input is applied in your example. Technically, if you released forward input, the Pawn should stop immediately. Perhaps you’re using Floating Pawn Movement for this?

Do you apply something during Tick?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5f425dc7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5f425dc7](https://forums.unrealengine.com/u/anonymous_user_5f425dc7)\
**Post date:** [December 7, 2019, 10:29am UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/5 "2019-12-07T10:29:03Z")

</div>

This is the complete moving setup at the moment:  
[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/8/c/c8c486088be4849f666a7c92850d2d8136c1d4ac.png) ](https://i.imgur.com/atgN6sa.png)  
It is hacky but I am currently redoing and the movement /rotation orientation issue was my first problem. I think I’ll just move all the forward/backwards movement nodes from the inputaxis to tick instead of trying to do the same thing in two places. Probably enough to just have a bool for the inputaxis and then in tick do the acceleration/deceleration based on that. I don’t have any good ideas for the main issue of this main question though. Here is what I tried earlier:  
[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/e/6/3e60b66ab0e42414c0984bbe693cedb36dbf0431.png) ](https://i.imgur.com/xvpNUIZ.png)  
Obviously that example doesn’t work but I wonder if it is even the right idea to try to use the addMovementInput node for this?  
I’d imagine the problem becomes easier to solve once I have moved the movement stuff to tick.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 7, 2019, 10:52am UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/6 "2019-12-07T10:52:41Z")

</div>

> I think I’ll just move all the  
> forward/backwards movement nodes from  
> the inputaxis to tick instead of  
> trying to do the same thing in two  
> places.

Do note that the Input Axis _is_ Ticking. It always spits out values, either what you’ve assigned or 0. If you look at my example, you’ll see that I’m utilising that 0 to keep moving even if nothing is pressed.

Perhaps that will inspire you.

* * *

But sure, you can use Inputs to _generate_ values for Tick to _use_. It’s a like a mini AI / automation movement.

Also, you’re using character movement here which comes with its own set of rules and overrides a lot of physics. It _can_ be a blessing and a curse at the same time.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5f425dc7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5f425dc7](https://forums.unrealengine.com/u/anonymous_user_5f425dc7)\
**Post date:** [December 7, 2019, 11:15am UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/7 "2019-12-07T11:15:14Z")

</div>

Yeah I know how the tick works :). I am not sure how to get the character to move to new direction after I release the w button and start turning. It still rotates but goes straight. Like a car that only steers when I press the throttle.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 7, 2019, 12:15pm UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/8 "2019-12-07T12:15:03Z")

</div>

> I am not sure how to get the character  
> to move to new direction after I  
> release the w button and start  
> turning.

If you want to use the _Character Movement Component_ and _Add Movement Input,_ you need to keep applying that forward direction constantly for the Pawn to move, regardless of the Axis Input value.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5f425dc7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5f425dc7](https://forums.unrealengine.com/u/anonymous_user_5f425dc7)\
**Post date:** [December 7, 2019, 12:50pm UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/9 "2019-12-07T12:50:10Z")

</div>

I just can’t figure out how to do that without ending up in a situation where the character just keeps going forward at constant speed

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 7, 2019, 1:06pm UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/10 "2019-12-07T13:06:35Z")

</div>

So what is supposed to happen when I release Forward, we gradually slow down to 0?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5f425dc7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5f425dc7](https://forums.unrealengine.com/u/anonymous_user_5f425dc7)\
**Post date:** [December 7, 2019, 1:11pm UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/11 "2019-12-07T13:11:32Z")

</div>

This is what I have now and it doesn’t work:

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/4/b/34bd02e87aa873360f841c3f761593075dd79db0.png)  
The way it is works is that first I check if there is button input active for forward or backwards. False is when there is none and this is the scenario that is the issue here. Then it checks if the character is going forward or backwards. Dot product compared to forward vector should be positive for forward and negative for backwards.

Then there is a if clause that triggers if the speed is above 0.02x max walk speed. No need to “steer” when near 0 speed. After that a small 0.05 addMovementInput is added.

Issue is that the movement input either does nothing or just locks the forward speed so I need to press s to stop. Or w if going backwards.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5f425dc7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5f425dc7](https://forums.unrealengine.com/u/anonymous_user_5f425dc7)\
**Post date:** [December 7, 2019, 1:28pm UTC](https://forums.unrealengine.com/t/tank-controls-keeping-forward-orientation-after-releasing-fwd-button-but-turning/459203/12 "2019-12-07T13:28:31Z")

</div>

Sorry, I missed this post. So what I’d want to happen is that when I release forward the speed slowly goes down to 0. That works pretty fine. But the issue is that after I release forward there is like 4 seconds before it stops from full speed. If during that time I press a or d to turn left or right the character turns but goes straight which means it ends up walking sideways. I’d want to steer the character with a and d so that it goes to the direction it is heading and not walk sideways. If I keep w or s pressed it works fine.
