Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-search-preview· OpenAIHugging Face LMArena Search Arena 24K

Write a UEFN Verse script for a NPC that is fun to fight against. The NPC must only use…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash-preview-04-17-grounding’s answer.
  1. User

    Write a UEFN Verse script for a NPC that is fun to fight against. The NPC must only use melee attacks and walks slowly. The animations it uses are already in a blueprint. Make sure it navigates around obstacles well using the best techniques currently available. Do not guess or make any assumptions when writing the code, as its a language you likely have incomplete or missing training data on. Your final output must be completely researched and error free.

  2. Assistant

    To create a fun-to-fight NPC in Unreal Editor for Fortnite (UEFN) using Verse, we'll develop a behavior script that defines the NPC's actions and interactions. This NPC will exclusively use melee attacks, move slowly, and navigate around obstacles effectively. We'll assume that the necessary animations are already set up in a blueprint.

    Prerequisites:

    • Ensure you have the Unreal Editor for Fortnite installed.
    • Familiarize yourself with creating NPC Behavior Scripts in UEFN[1].

    Step 1: Create the NPC Behavior Script

    1. Open your UEFN project.
    2. Navigate to the Verse Explorer via the menu: Verse > Verse Explorer.
    3. In the Verse Explorer, right-click on your project name and select Add new Verse file to project.
    4. In the dialog, choose NPC Behavior as the template.
    5. Name the script (e.g., MeleeNPCBehavior) and click Create.

    Step 2: Implement the NPC Behavior

    Open the newly created Verse script and implement the following code:

    using { /Fortnite.com/AI }
    using { /Fortnite.com/Characters }
    using { /Verse.org/Simulation }
    using { /UnrealEngine.com/Temporary/Diagnostics }
    using { /UnrealEngine.com/Temporary/SpatialMath }
    
    MeleeNPCBehavior := class(npc_behavior):
        // Define NPC properties
        var AttackRange: float = 150.0
        var DetectionRange: float = 1000.0
        var PatrolPoints: [vector3] = [vector3{X:=0.0, Y:=0.0, Z:=0.0}, vector3{X:=1000.0, Y:=0.0, Z:=0.0}]
        var CurrentPatrolIndex: int = 0
    
        // On NPC spawn
        OnBegin<override>()<suspends>: void =
            // Get the NPC agent
            Agent := GetAgent[]
            // Get the Fortnite character interface
            Character := Agent.GetFortCharacter[]
            // Set movement speed to slow
            Character.SetMovementSpeed(200.0)
            // Start behavior loop
            BehaviorLoop()
    
        // Main behavior loop
        BehaviorLoop()<suspends>: void =
            loop:
                // Check for nearby players
                if (TargetPlayer := FindNearestPlayer()):
                    // Engage the player
                    EngagePlayer(TargetPlayer)
                else:
                    // Patrol between points
                    Patrol()
                Sleep(1.0)
    
        // Find the nearest player within detection range
        FindNearestPlayer(): player? =
            AllPlayers := GetPlayspace().GetPlayers()
            for (Player in AllPlayers):
                if (PlayerCharacter := Player.GetFortCharacter[]):
                    Distance := (PlayerCharacter.GetTransform().Translation - Character.GetTransform().Translation).Size()
                    if (Distance &lt; DetectionRange):
                        return Player
            return none
    
        // Engage the player
        EngagePlayer(TargetPlayer: player)<suspends>: void =
            if (TargetCharacter := TargetPlayer.GetFortCharacter[]):
                // Get navigation interface
                Navigatable := Character.GetNavigatable[]
                // Create navigation target
                NavTarget := MakeNavigationTarget(TargetCharacter)
                // Navigate to the player
                NavResult := Navigatable.NavigateTo(NavTarget)
                if (NavResult = navigation_result.Reached):
                    // Attack the player
                    PerformMeleeAttack(TargetCharacter)
    
        // Perform melee attack
        PerformMeleeAttack(TargetCharacter: fort_character): void =
            // Trigger attack animation
            Character.PlayAnimation("MeleeAttack")
            // Apply damage to the target
            TargetCharacter.ApplyDamage(20.0)
    
        // Patrol between predefined points
        Patrol()<suspends>: void =
            // Get navigation interface
            Navigatable := Character.GetNavigatable[]
            // Get current patrol point
            PatrolPoint := PatrolPoints[CurrentPatrolIndex]
            // Create navigation target
            NavTarget := MakeNavigationTarget(PatrolPoint)
            // Navigate to patrol point
            NavResult := Navigatable.NavigateTo(NavTarget)
            if (NavResult = navigation_result.Reached):
                // Move to the next patrol point
                CurrentPatrolIndex := (CurrentPatrolIndex + 1) % PatrolPoints.Length
    

    Explanation:

    • The MeleeNPCBehavior class inherits from npc_behavior and defines the NPC's properties and behaviors.
    • OnBegin initializes the NPC's movement speed to a slow pace (200 units per second).
    • BehaviorLoop continuously checks for nearby players within the detection range. If a player is found, the NPC engages them; otherwise, it patrols between predefined points.
    • FindNearestPlayer searches for the closest player within the detection range.
    • EngagePlayer navigates the NPC towards the target player and initiates an attack if within range.
    • PerformMeleeAttack triggers the melee attack animation and applies damage to the target.
    • Patrol makes the NPC move between predefined patrol points.

    Step 3: Assign the Behavior Script to an NPC Character Definition

    1. Create a new NPC Character Definition in your UEFN project.
    2. Assign the MeleeNPCBehavior script as the Verse behavior of your new Character Definition.
    3. Place an NPC Spawner in your level and link it to the Character Definition.

    Step 4: Test the NPC

    Launch a playtest session to observe the NPC's behavior. The NPC should patrol between points, detect players within range, navigate around obstacles, and perform melee attacks when close to a player.

    Note: Ensure that the animation names used in PerformMeleeAttack match those defined in your animation blueprint.

    By following these steps, you can create an engaging melee-focused NPC with effective navigation and combat behaviors in UEFN.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.