How do you move a prop after spawning it in the world?

I am trying to create a projectile that spawns a prop on the players location and then moves forward from that location. Eventually want to add physics and collision detection if possible but for now just trying to get the object to move.

using {/EpicGames.com/Simulation}
using {/Verse.org/Simulation}
using {/Fortnite.com/Game}
using {/EpicGames.com/Temporary/SpatialMath}
using {/Fortnite.com/Characters}
using { /Fortnite.com/Devices }
using { /EpicGames.com/Temporary/Diagnostics }
using {/Verse.org/Assets}
using {/Fortnite.com/Playspaces}
using {/Verse.org/Simulation/Tags}
using { /Fortnite.com/Devices/CreativeAnimation}
using {/Fortnite.com/Devices/Animation}

 #Goal is to create a spawnable prop that acts as a projectile. 
    #[✓] need to get player location [✓]
    #[✓] spawn prop at player location [✓]
    #From the spawned location I want the projectile to move forward in the direction the player was facing when it was spawned.
    #eventually would like to apply physics to this so projectiles can fall down or float away
    #When the projectile collides with players I want it to cause damage
    #when it hits terrain or props it stops with an adjustable time before it disappears


AweDamProjectile := class(creative_device){
    @editable MyRemote : signal_remote_manager_device = signal_remote_manager_device{}
    @editable animDevice : Prop2Fire = animation_controller
    @editable Prop2Fire:creative_prop_asset := DefaultCreativePropAsset
    @editable SpawnDistance: float = 2.45
    @editable ProjSpeed: float = 0.5
    @editable PropMoverProj: prop_mover_device = prop_mover_device{}
    

    OnBegin<override>()<suspends>:void=
        MyRemote.PrimaryActivationEvent.Subscribe(Function_1)
        MyRemote.SecondaryFireEvent.Subscribe(Function_2)
        

    Function_1(Player:player):void=
        Print("Function 1 activated", ?Duration := 20.0)
        Players:[]player := Self.GetPlayspace().GetPlayers()
        for (Char -> Index : Players) {
            if (FortChar := Players[Char].GetFortCharacter[]) {
            tempprop:=SpawnProp(Prop2Fire,(((FortChar.GetTransform().Rotation.GetLocalForward()) * SpawnDistance) + FortChar.GetTransform().Translation),FortChar.GetTransform().Rotation)
            
            tempprop.MoveTo((((tempprop.GetTransform().Rotation.GetLocalForward()) * SpawnDistance) + tempprop.GetTransform().Translation), tempprop.GetTransform().Rotation, ProjSpeed)
            }
             
        
        }
    
        

    Function_2(Player:player):void=
        Print("Function 2 activated", ?Duration := 20.0)
        
    
}
    
        

Hi Awe! I think i’ve managed to solve your problem. There were two things I had to fix:

1: you can’t move a creative_prop_asset. This isn’t an actual world item, it’s the asset used to spawn one in. You also can’t move the ‘tempprop’ in the first function, because ‘tempprop’ is actually two things: The prop itself, and another value that shows whether the prop was successfully loaded. To reference the actual prop item, you have to reference ‘tempprop(0)’, which is the actual prop.

2: You can’t use the MoveTo method in a non [suspends] function. To fix this, spawn{} the function. (Thanks Axel for that one!)

I was having trouble opening the editor, but once I removed the ‘getLocalForward’ from the tempprop it worked fine. You may have to tweak the values a bit, but it should actually work!
projectile_device.verse (2.4 KB)

2 Likes

Will have to play with this! Thank you!!!

Had some help last night from @BrendannnD and we got things into a good state! I think we used some different methods! I’ll post what we ended up with below so others can use this too!

Function_1(Player:player):void=
        Print("Function 1 activated", ?Duration := 20.0)
        spawn {Function_2(Player)}        

    Function_2(Player:player)<suspends>:void=
        Print("Function 2 activated", ?Duration := 20.0)
        Players:[]player := Self.GetPlayspace().GetPlayers()
        for (Char -> Index : Players) {
            if (FortChar := Players[Char].GetFortCharacter[]) { 
                Logger.Print("RUN!!!")
                tempprop:= SpawnProp(Prop2Fire,(((FortChar.GetTransform().Rotation.GetLocalForward()) * SpawnDistance) + FortChar.GetTransform().Translation),FortChar.GetTransform().Rotation)
                if (CreativePropInst.TeleportTo[vector3{X:=FortChar.GetTransform().Translation.X, Y:=FortChar.GetTransform().Translation.Y, Z:=FortChar.GetTransform().Translation.Z}, IdentityRotation()]):
                    CreativePropInst.MoveTo(vector3{X:=CreativePropInst.GetTransform().Translation.X, Y:=CreativePropInst.GetTransform().Translation.Y, Z:=CreativePropInst.GetTransform().Translation.Z}, AddToYaw(FortChar.GetTransform().Rotation, 90.0), 0.01)
                    CreativePropInst.MoveTo((((FortChar.GetTransform().Rotation.GetLocalForward()) * MoveToDistance) + FortChar.GetTransform().Translation), AddToYaw(FortChar.GetTransform().Rotation, 90.0), ProjSpeed)
            }
        }     
    AddToYaw(Rotation : rotation, Offset : float) : rotation = {
        YPR := Rotation.GetYawPitchRollDegrees()
        if (yaw := YPR[0], pitch := YPR[1], roll := YPR[2]):
            return MakeRotationFromYawPitchRollDegrees(yaw+Offset, pitch, roll)
        return MakeRotationFromYawPitchRollDegrees(0.0, 0.0, 0.0)
    }
}
1 Like