Home - Vaei/TurnInPlace GitHub Wiki
Overview
[!IMPORTANT] Actor-Based Turn in Place (TIP) Solution. A superior substitute to Mesh-Based Turn in Place without the endless list of issues that comes with it.
Browse this Wiki using the sidebar to learn how to make use of TurnInPlace.
Features
Orient to Movement
Like BOTW and other adventure games, when we tap an input key, the character will continue to rotate while stationary until it faces the last input vector.
We combine this with the turn in place system, and the result is that we have turn in place with orient to movement.
Strafe Direct
This is the mode used for shooter games such as LyraStarterGame. It keeps our character facing the control rotation (camera) at all times.
It has a MaxAngle clamp that prevents us from being able to shoot behind us. Its fully reliable and doesn't fail; there are no edge cases.
Strafe Desired
This mode works very well for melee strafing. Unlike Strafe Direct, this mode only attempts to face the control rotation, and it is limited by the RotationRate
on the UCharacterMovementComponent
. If you don't require looking at the screen center at all times, this is a much better means of strafing.
Play Rate Modifiers
When reaching the max turn angle, you can optionally have the turn animation play at a faster rate in an effort to keep up with the player spinning their camera a little better. There is also the option to maintain max angle play rate for the remainder of the animation if we've reached it even once, which stops the play rate jittering with mouse constantly re-entering and re-exiting the max angle.
There is also another play rate modifier for changing directions; if we're currently in a turn left animation but the player rapidly spun their camera and now its time to play a turn right animation, it will use the play rate on direction change property to rapidly complete the now redundant turn. We don't snap and we don't get stuck in the wrong turn; it completes quickly.
Toggle State
We have the ability to lock the turn in place. When the turn in place is locked we will face the direction we were facing when it was locked and remain facing that way.
And we have the ability to pause the turn in place. When the turn in place is paused your rotation will work as if the turn in place system doesn't exist. This is very useful for root motion montages that want to take over the movement.
[!TIP] Toggle State behaviours are different between each movement system, especially when you start moving!
Root Motion Montage Handling
When we play a networked root motion montage, a call is made to the UTurnInPlace
component that you can override, called ShouldIgnoreRootMotionMontage()
so you can decide which montages should pause the turn in place and take over, or not.
The Anim Set has a lot of parameters that change this behaviour without requiring an override, so start there.
Robust Implementation
You can return an anim set based on the current animation state using the included interface
Each AnimSet can define it's own Step Sizes, and each Turn Mode can define it's own Min and Max Turn Angle. So you're not bound by the same step sizes, etc., between stances or anim states.
There are settings to customize the selection behaviour that determines which animation to select based on the Turn Angle.
And you can override functions on the UTurnInPlace
component to modify the turn in place result during runtime.
Multiplayer Ready
Simulations are highly accurate and did not require additional replication to achieve between the server and local client.
The TurnOffset
is compressed to a uint16 and sent to simulated proxies who decompress and apply it. Even with high latency the simulated proxies turn in place smoothly, without jitter, and accurately.
The only potential to come out of sync is a result of UE5 itself compressing the rotation, so you could just barely trigger a turn on the server and then not complete it on the local client, however this is difficult to achieve even when trying to do so intentionally, and will never be more than that single step out of sync, and will re-sync automatically when the character moves.
Otherwise, the system is flawless.
Exponential NetworkSmoothingMode
Using Epic's Mesh-Based Turn In Place (Lyra, Fortnite) requires that you use the archaic Linear NetworkSmoothingMode. You don't need to do that, you can use Exponential with this system, and you should! It looks great.
Lets not degrade the result of our entire project for something as unimportant as Turn In Place :(
Thread Safe
The included demo setup for this plugin updates in Worker Threads to allow for async updates following best practices for ideal performance. For a demo it is not imperative, but it is intended that you copy the setup into your own anim graph.