Thank you @swaggod !
MoveTo indeed functions in cases like moving NPCs, but seems like there’s something, somewhere, in UEFN, not Verse, acting like an “anticheat” of sorts, snapping the Prop back to origin after the transform…
Being stubborn, I’m keeping iterating on the script, trying to make it as minimalist as possible…
for the record, this is where I am at
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /Verse.org/Verse }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
# This class defines a device that makes a cube follow the player
Draggable := class(creative_device):
@editable
Cube : creative_prop = creative_prop{}
@editable
Delay : float = 1.0 # delay between each movement in seconds
@editable
MinDistance : float = 200.0 # minimum distance to maintain from player
@editable
VolumeTrigger: volume_device = volume_device{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Print("Device initialized and waiting for player to enter volume.", ?Duration := 6.0)
VolumeTrigger.AgentEntersEvent.Subscribe(TriggerWakeupAsync)
# Function to handle the event asynchronously
TriggerWakeupAsync(InPlayer:agent):void =
spawn{TriggerWakeup(InPlayer)}
# Async function that handles the logic when a player enters the volume
TriggerWakeup(InPlayer:agent)<suspends>:void =
if (FortCharacter := InPlayer.GetFortCharacter[]):
Print("Player entered volume and attached!", ?Duration := 6.0)
FollowPlayer(FortCharacter)
# Function to make the cube follow the player
FollowPlayer(Player:fort_character)<suspends>:void=
loop:
Sleep(Delay)
PlayerPosition := Player.GetTransform().Translation
CubePosition := Cube.GetTransform().Translation
Direction := NormalizeVector(PlayerPosition - CubePosition)
DistanceToPlayer := VectorDistance(PlayerPosition, CubePosition)
if (DistanceToPlayer > MinDistance):
TargetPosition := PlayerPosition - Direction * MinDistance
Cube.MoveTo(TargetPosition, Cube.GetTransform().Rotation, 0.1)
# Function to normalize a vector
NormalizeVector(Vector:vector3) : vector3 =
Magnitude := Vector.Length()
if (Magnitude > 0.0):
return Vector / Magnitude
else:
return Vector
# Function to calculate the distance between two vectors
VectorDistance(VectorA:vector3, VectorB:vector3) : float =
return (VectorA - VectorB).Length()
It compiles, runs in game… still, prop snaps backto original position immediately.
Odd.
I will keep working on it and report my findings here.
… Yet Another wasted weekend ![]()