NPC Behavior Navigatable GoToPoint Programming Question

Hey! I’m trying to send an NPC 24000 Unreal Units in the X direction relative to the NPC spawner’s direction. I have this code that sends an NPC to a specific point, but how would I send an NPC in a specific direction and distance instead of a specific point?

            loop:
                # Create a random offset from the spawn point to walk toward.
                GoToPoint := NPCSpawnPoint + vector3{X := 24000.0,
                                                     Y := 0.0,
                                                     Z := 0.0 }
                

Sorry, thanks.

This is what I tried next but it didn’t work:

            # Save the position of your character which we'll use to generate more points to move to from.
            NPCSpawnPoint := Character.GetTransform().Translation
            # Get the NPCSpawner's rotation
            NPCSpawnPointRotation := Character.GetTransform().Rotation
            # Define the base forward vector
            BaseForwardVector := vector3{X := 1.0, Y := 0.0, Z := 0.0}
            # Rotate the base forward vector by the NPCSpawner's rotation
            ForwardDirection := NPCSpawnPointRotation.RotateVector(BaseForwardVector)
            # Scale the forward direction by the desired distance
            MovementVector := ForwardDirection * 24000.0

            loop:
                # Create a random offset from the spawn point to walk toward.
                GoToPoint := NPCSpawnPoint + MovementVector

Where I’m at now, because that didn’t work…is wondering how do I reference the NPC spawner’s transforms. I think I’m referencing the character’s transforms which don’t seem to be doing it.

bruh this forum is empty, people are waiting for any response weeks and months, better hang out in Warforge discord or somewhere with active community, those forums are a dead space with no crickets :cricket:

I’m browsing those threads in search of useful info and examples and see more unanswered threads than stars in the sky…

Hah, I’m on there as well.

Today I’m going to mess around with “Tags” and see if that gets me any further

by the way what is the NPC class you’re using, the new “npc_behavior” ? (check out this tutorial, seems :fire: Create your own NPC Medic)

1 Like

Yea I was using the new one. I did the “Create your own medic” very useful, but still unable to achieve what I was trying to through it

Something like this should work

keep in mind this doesn’t account for changes in height that’s a whole different can of worms

but if point a to point b is flat, this should do the trick so long as the spawners local x is facing the direction you want whatever you’re moving to go

i used a creative prop here but so long as whatever you’re moving has access to stuff like GetTransform() you should be good to go

Edit : let me know if there are syntax errors ( I typed this out on the website )

@editable Spawner : player_spawner_device = player_spawner_device{}
    @editable Prop : creative_prop = creative_prop{}

    Magnitude(vector:vector3):float=
        return Sqrt(Pow(vector.X, 2.0) + Pow(vector.Y, 2.0) + Pow(vector.Z, 2.0))

    Normalize(vector:vector3):vector3=
        Mag := Magnitude(vector)
        return vector3{X := vector.X/Mag, Y := vector.Y/Mag, Z:= vector.Z/Mag}

    Move_NPC(prop:creative_prop, spawner:player_spawner_device)<suspends>:void= #just used a creative prop here as an example you can pass in whatever you want
        prop_loc := prop.GetTransform().Translation
        spawner_loc := spawner.GetTransform().Translation
        spawner_rot := spawner.GetTransform().Rotation
        spawner_yaw_pitch_roll := spawner_rot.GetYawPitchRollDegrees()
        Move_Time := 15.0

        if(NewYaw := spawner_yaw_pitch_roll[0] - 90.0):
            if(Corrected_Spawner_Rot := MakeRotationFromYawPitchRollDegrees(NewYaw, spawner_yaw_pitch_roll[1], spawner_yaw_pitch_roll[2])):
                Spawner_Local_Forward := Corrected_Spawner_Rot.GetLocalForward()
                Normalized_Forward_Vector := Normalize(Spawner_Local_Forward)
                Dist := 24000.0
                Target_Location : vector3 = vector3:
                    X := prop_loc.X + (Normalized_Forward_Vector.X * Dist)
                    Y := prop_loc.Y + (Normalized_Forward_Vector.Y * Dist)
                    Z := prop_loc.Z
                prop.MoveTo(Target_Location, spawner_rot, Move_Time)
1 Like

Ok cool, let me check this out! Thanks Jeremy

You can use InitialPosition + SomeRotation.RotateVector(vector3{X := MyDistance}), it will generate a point in the direction of SomeRotation

2 Likes