I want a prop to rotate to where the player is looking.

So I don’t know how to do so a prop follows the player’s looking direction. So far I got a code that follows the player, and it works pretty well, but I want that same prop to rotate where the player is looking. I am doing a flashlight, and, like I said it works pretty well, I used a spotlight and it looks like a flashlight, but I want this same prop to rotate to where the player is looking.

This is the code:

prop_follows_player_device := class(creative_device):

    @editable
    FollowerProp : creative_prop = creative_prop{}

    DoFollowPlayer()<suspends> : void =
        loop:
            if (PlayerList := GetPlayspace().GetPlayers(), FortniteCharacter := PlayerList[0].GetFortCharacter[]):
                PlayerPosition : vector3 = FortniteCharacter.GetTransform().Translation
                FollowerProp.MoveTo(PlayerPosition, rotation{},0.2)                
                
            else:
                break
            Print("Follow")
    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=

        DoFollowPlayer()
1 Like

You can simply call GetViewRotation() on your FortCharacter to get the current look rotation of the player. So to make something have the same rotation that the player is aiming, just do:

FollowerProp.MoveTo(PlayerPosition, FortniteCharacter.GetViewRotation(), 0.2)

Pro tip: It’s worth reading/skimming through the entire Fortnite.digest.verse file at least once, so you at least give your brain a hint on what can be done and where :slight_smile: Also the other two verse digests are useful to skim, though do be aware that some things are not yet applicable (e.g. placeholder classes and such).

4 Likes

Really appreciate your help :pray:

It works perfect!, But for some reason if I turn around the light starts moving like crazy, even if i don’t move the camera at all, do you know a workaround for this? =)

It might be colliding with something. As a test, try to make the prop floating in the sky. If that’s no good, then I’m not sure - how exactly are you turning around without moving the camera? Doesn’t one require the other?