Tracking Linear And Angular Player Velocity
61,741 Views
-
using { /Fortnite.com/Devices } players_velocity_tracker_device := class<concrete>(creative_device): # Tracking variables var PlayersLastPositionAndRotation : [agent]tuple(vector3, rotation) = map{} var PlayersVelocity : [agent]tuple(vector3, float) = map{} @editable DeltaTime : float = 0.0333 # 0.033 = 30 FPS, 0.016 = 60 FPS, 0.0083 = 120 fps ... @editable DebugUpdateTime : float = 0.0 OnBegin<override>()<suspends>:void= spawn{UpdatePlayersVelocity()} if(DebugUpdateTime > 0.0): spawn{DebugOutput()} GetPlayerLinearVelocity<public>(Agent : agent)<decides><transacts>:vector3= var ReturnValue : ?vector3 = false if(PlayersVelocity[Agent], set ReturnValue = option{PlayersVelocity[Agent](https://dev.epicgames.com/community/snippets/GRVN/0)}): ReturnValue? GetPlayerLinearVelocityLength<public>(Agent : agent)<decides><transacts>:float= var ReturnValue : ?float = false if(PlayersVelocity[Agent], set ReturnValue = option{PlayersVelocity[Agent](https://dev.epicgames.com/community/snippets/GRVN/0).Length()}): ReturnValue? GetPlayerAngularVelocityRadians<public>(Agent : agent)<decides><transacts>:float= var ReturnValue : ?float = false if(PlayersVelocity[Agent], set ReturnValue = option{PlayersVelocity[Agent](https://dev.epicgames.com/community/snippets/GRVN/1)}): ReturnValue? GetPlayerAngularVelocityDegree<public>(Agent : agent)<decides><transacts>:float= var ReturnValue : ?float = false if(VelocityInDegrees := GetPlayerAngularVelocityRadians[Agent] * 180.0 / PiFloat): set ReturnValue = option{VelocityInDegrees} ReturnValue? UpdatePlayersVelocity<internal>()<suspends>:void= loop: for(i := 0..GetPlayspace().GetPlayers().Length-1, PlayerAgent := GetPlayspace().GetPlayers()[i]): if(CFortChar := PlayerAgent.GetFortCharacter[], CFortChar.IsActive[]): CurrentPositionCharacter := CFortChar.GetTransform().Translation CurrentRotationCharacter := CFortChar.GetViewRotation() if(LastPosition := PlayersLastPositionAndRotation[PlayerAgent](https://dev.epicgames.com/community/snippets/GRVN/0), LastRotation := PlayersLastPositionAndRotation[PlayerAgent](https://dev.epicgames.com/community/snippets/GRVN/1), cPlayerVelocity := ((CurrentPositionCharacter - LastPosition) / DeltaTime, (CurrentRotationCharacter.GetYawPitchRollDegrees()[0] - LastRotation.GetYawPitchRollDegrees()[0]) / DeltaTime), set PlayersLastPositionAndRotation[PlayerAgent] = (CurrentPositionCharacter, CurrentRotationCharacter)): if(set PlayersVelocity[PlayerAgent] = cPlayerVelocity): # UEFN APIs will change in the future, so take in mind this is provvisory
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.