Skip to content
TheChatArchiveThe Chat Archive
Perplexitysonar-pro-high· PerplexityHugging 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 gpt-4o-search-preview-high-loc’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. Make sure to research ways to make enemies fun to fight and apply the most fun and compatible findings. 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. Perplexity Assistant

    Creating a Fun Melee NPC in UEFN

    Creating a fun melee NPC requires careful consideration of movement patterns, attack behaviors, and player interaction. The script below implements a slow-moving melee enemy that navigates around obstacles, detects players, and engages them with melee attacks when in range.

    Core NPC Behavior Script

    using { /Fortnite.com/AI }
    using { /Fortnite.com/Characters }
    using { /Fortnite.com/Devices }
    using { /Verse.org/Simulation }
    using { /UnrealEngine.com/Temporary/SpatialMath }
    using { /Verse.org/Random }
    
    # A custom melee NPC that slowly approaches players and attacks them
    melee_enemy_behavior<public> := class(npc_behavior):
        # How far the NPC can detect players
        @editable
        DetectionRange : float = 5000.0
        
        # How close the NPC needs to be to attack
        @editable
        AttackRange : float = 200.0
        
        # How much damage each attack does
        @editable
        AttackDamage : float = 15.0
        
        # How long to wait between attacks
        @editable
        AttackCooldown : float = 1.5
        
        # How close the NPC needs to get to navigation targets
        @editable
        ReachRadius : float = 150.0
        
        # Reference to teleport VFX for spawning/despawning effects
        @editable
        SpawnVFX : vfx_spawner_device = vfx_spawner_device{}
        
        # Variable to track the current target player
        var CurrentTarget : ?player = false
        
        # Variable to track if the NPC is currently attacking
        var IsAttacking : logic = false
        
        # OnBegin is called when the NPC spawns
        OnBegin<override>()<suspends>:void =
            # Get the agent (NPC) that this behavior is attached to
            if (Agent := GetAgent[]):
                # Get the character from the agent
                if (Character := Agent.GetFortCharacter[]):
                    # Start the main behavior loop
                    spawn { MainBehaviorLoop(Character) }
        
        # Main loop that controls the NPC's behavior
        MainBehaviorLoop(Character : fort_character)<suspends>:void =
            # Get navigation and animation interfaces
            if (NavigationInterface := Character.GetNavigationInterface[]):
                if (AnimationInterface := Character.GetAnimationInterface[]):
                    # Start the main loop
                    loop:
                        # Check if the character is still alive
                        if (not Character.IsActive[]):
                            break
                        
                        # Find the nearest player
                        FindNearestPlayer(Character)
                        
                        # If we have a target, pursue them
                        if (Target := CurrentTarget?):
                            if (TargetCharacter := Target.GetFortCharacter[]):
                                # Get target location
                                TargetLocation := TargetCharacter.GetTransform().Translation
                                
                                # Calculate distance to target
                                CharacterLocation := Character.GetTransform().Translation
                                DistanceToTarget := Distance(CharacterLocation, TargetLocation)
                                
                                # If close enough to attack and not currently attacking
                                if (DistanceToTarget &lt;= AttackRange and not IsAttacking):
                                    # Stop navigation
                                    NavigationInterface.StopNavigation()
                                    
                                    # Face the target
                                    FaceTarget(Character, TargetLocation)
                                    
                                    # Attack the target
                                    spawn { PerformAttack(Character, AnimationInterface, TargetCharacter) }
                                # If not in attack range, navigate toward the target
                                else if (DistanceToTarget &gt; AttackRange):
                                    # Navigate to the target
                                    NavigationInterface.NavigateTo(TargetLocation, ReachRadius)
                        
                        # Wait a short time before the next update
                        Sleep(0.2)
        
        # Find the nearest player within detection range
        FindNearestPlayer(Character : fort_character):void =
            # Get all players in the game
            AllPlayers := GetPlayspace().GetPlayers()
            
            # Variables to track the nearest player
            var NearestPlayer : ?player = false
            var NearestDistance : float = DetectionRange
            
            # Get the character's current location
            CharacterLocation := Character.GetTransform().Translation
            
            # Check each player
            for (Player : AllPlayers):
                if (PlayerCharacter := Player.GetFortCharacter[]):
                    # Get player location
                    PlayerLocation := PlayerCharacter.GetTransform().Translation
                    
                    # Calculate distance
                    DistanceToPlayer := Distance(CharacterLocation, PlayerLocation)
                    
                    # If this player is closer than the current nearest
                    if (DistanceToPlayer &lt; NearestDistance):
                        set NearestPlayer = option{Player}
                        set NearestDistance = DistanceToPlayer
            
            # Update the current target
            set CurrentTarget = NearestPlayer
        
        # Make the NPC face a specific location
        FaceTarget(Character : fort_character, TargetLocation : vector3)<suspends>:void =
            if (FocusInterface := Character.GetFocusInterface[]):
                # Get the direction to the target
                CharacterLocation := Character.GetTransform().Translation
                DirectionToTarget := TargetLocation - CharacterLocation
                
                # Create a focus point in the direction of the target
                FocusPoint := CharacterLocation + DirectionToTarget
                
                # Make the character focus on that point
                FocusInterface.FocusOnLocation(FocusPoint, 0.5)
        
        # Perform an attack against the target
        PerformAttack(Character : fort_character, AnimationInterface : animation_controller, TargetCharacter : fort_character)<suspends>:void =
            # Set attacking flag
            set IsAttacking = true
            
            # Play attack animation
            AnimationInterface.PlayAnimation(action{identifier := "Attack"})
            
            # Wait for the animation to reach the point where damage should be applied
            # This timing should match when the attack animation shows the hit
            Sleep(0.6)
            
            # Check if we're still in range to apply damage
            CharacterLocation := Character.GetTransform().Translation
            TargetLocation := TargetCharacter.GetTransform().Translation
            DistanceToTarget := Distance(CharacterLocation, TargetLocation)
            
            # Apply damage if still in range
            if (DistanceToTarget &lt;= AttackRange + 50.0):
                TargetCharacter.Damage(AttackDamage)
            
            # Wait for the attack cooldown
            Sleep(AttackCooldown)
            
            # Reset attacking flag
            set IsAttacking = false
        
        # Called when the NPC is about to be destroyed
        OnEnd<override>():void =
            # Clean up any resources if needed
            set CurrentTarget = false
            set IsAttacking = false
    

    Making the NPC Fun to Fight

    The script above implements several key features that make the NPC fun to fight against:

    1. Predictable Movement: The NPC moves slowly, giving players time to react and strategize.

    2. Telegraph Attacks: The attack animation plays before damage is applied, giving players a chance to dodge.

    3. Cooldown Between Attacks: The NPC has a cooldown period after each attack, creating windows of opportunity for players to counter-attack.

    4. Spatial Awareness: The NPC navigates around obstacles using Fortnite's built-in navigation system.

    5. Player Tracking: The NPC will pursue the nearest player, creating a sense of threat and urgency.

    Navigation Implementation

    The script uses Fortnite's built-in navigation system through the NavigationInterface. This interface handles pathfinding around obstacles automatically. The NavigateTo function takes a target location and a reach radius, which determines how close the NPC needs to get to consider the destination reached.

    Attack Mechanics

    The attack system is designed to be fair and readable to players:

    1. The NPC stops moving when in attack range
    2. It faces the player before attacking
    3. There's a delay between the start of the animation and when damage is applied
    4. After attacking, there's a cooldown period before the NPC can attack again

    Setting Up the NPC

    To use this script:

    1. Create a new Verse file in your UEFN project
    2. Copy the code above into the file
    3. Create an NPC Character Definition with type set to "Custom"
    4. Set the Verse Behavior to your new script
    5. Place an NPC Spawner in your level and set it to use your Character Definition

    Additional Customization

    You can adjust the following parameters to fine-tune the NPC's behavior:

    • DetectionRange: How far the NPC can see players
    • AttackRange: How close the NPC needs to be to attack
    • AttackDamage: How much damage each attack does
    • AttackCooldown: How long to wait between attacks
    • ReachRadius: How close the NPC needs to get to navigation targets

    These parameters can be adjusted in the UEFN editor after assigning the script to an NPC.

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