Last active
March 28, 2023 22:48
-
-
Save MattRix/39e8c09ac5ad5727f4cd3a9ac2765486 to your computer and use it in GitHub Desktop.
Movement Detector Device in Verse for UEFN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using { /Verse.org/Simulation } | |
using { /UnrealEngine.com/Temporary/SpatialMath } | |
using { /Fortnite.com/Devices } | |
using { /Fortnite.com/Characters } | |
movement_detector_device := class(creative_device): | |
@editable | |
MinimumMovementDistance : float = 100.0 | |
OnBegin<override>()<suspends>:void = | |
for(Player : GetPlayspace().GetPlayers()): | |
OnPlayerAdded(Player) | |
GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded) | |
OnPlayerAdded<private>(Player : player):void = | |
spawn { CheckForMovement(Player) } | |
CheckForMovement<private>(Player : player)<suspends>:void = | |
if(FortChar := Player.GetFortCharacter[]): | |
var OldPos : vector3 = FortChar.GetTransform().Translation | |
loop: | |
NewPos := FortChar.GetTransform().Translation | |
Dist := Distance(NewPos,OldPos) | |
if(Dist > MinimumMovementDistance): | |
set OldPos = NewPos | |
HandlePlayerMoved(Player) | |
Sleep(0.1) | |
if(not GetPlayspace().GetPlayers().Find[Player]) then break #player was removed | |
HandlePlayerMoved(Player : player) : void = | |
Print("Player Moved!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment