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.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Designing an engaging melee-focused NPC in Unreal Editor for Fortnite (UEFN) involves creating a character that offers a fun and challenging combat experience. To achieve this, we'll implement a state machine to manage the NPC's behaviors, ensuring it navigates obstacles effectively and interacts with the player in a dynamic manner.
Key Considerations for Engaging Enemy AI:
Predictable Yet Varied Behavior: Players should be able to anticipate enemy actions to some extent, allowing for strategic planning. However, introducing variability prevents encounters from becoming monotonous. (blackshinobi.dev)
Emotional States and Reactions: Incorporating emotional responses, such as aggression or fear, can make enemies feel more lifelike and responsive to player actions. (blackshinobi.dev)
Clear Signaling: Providing visual and audio cues for enemy actions helps players react appropriately, enhancing the combat experience. (blackshinobi.dev)
Effective Navigation: Ensuring the NPC can navigate around obstacles and reach the player is crucial for maintaining engagement. (dev.epicgames.com)
Implementing the NPC in Verse:
Below is a Verse script that defines an NPC with melee attacks, slow movement, and effective navigation. The NPC uses a state machine to manage its behaviors, including idling, chasing the player, and attacking.
verse
// Define the NPC class
class MeleeNPC extends npc_behavior:
// Define states
enum State { Idle, Chase, Attack }
var currentState: State = State.Idle
// Define properties
@editable
var detectionRadius: float = 1000.0 // Distance to detect the player
@editable
var attackRange: float = 200.0 // Range to initiate attack
@editable
var attackCooldown: float = 2.0 // Time between attacks
@editable
var movementSpeed: float = 150.0 // Slow movement speed
var lastAttackTime: float = 0.0
var player: fort_character
// On NPC spawn
OnBegin<override>(): void =
// Find the player character
player = GetPlayerCharacter()
// Start the behavior loop
BehaviorLoop()
// Main behavior loop
BehaviorLoop(): void =
loop:
switch (currentState):
case State.Idle:
IdleBehavior()
case State.Chase:
ChaseBehavior()
case State.Attack:
AttackBehavior()
Sleep(0.1) // Small delay to prevent tight looping
// Idle behavior
IdleBehavior(): void =
if (IsPlayerInRange(detectionRadius)):
currentState = State.Chase
// Chase behavior
ChaseBehavior(): void =
if (IsPlayerInRange(attackRange)):
currentState = State.Attack
else:
NavigateToPlayer()
// Attack behavior
AttackBehavior(): void =
if (TimeSince(lastAttackTime) >= attackCooldown):
PerformAttack()
lastAttackTime = GetTime()
else if (!IsPlayerInRange(attackRange)):
currentState = State.Chase
// Check if player is within a certain range
IsPlayerInRange(range: float): bool =
return DistanceToPlayer() <= range
// Calculate distance to player
DistanceToPlayer(): float =
return VectorDistance(GetTransform().Translation, player.GetTransform().Translation)
// Navigate towards the player
NavigateToPlayer(): void =
var navTarget = MakeNavigationTarget(player.GetTransform().Translation)
var navResult = GetNavigatable().NavigateTo(navTarget, ?movementSpeed := movementSpeed)
if (navResult != navigation_result.success):
// Handle navigation failure (e.g., obstacle encountered)
HandleNavigationFailure()
// Perform attack
PerformAttack(): void =
// Trigger attack animation and logic
TriggerAttackAnimation()
// Apply damage to player
ApplyDamageToPlayer()
// Handle navigation failure
HandleNavigationFailure(): void =
// Implement logic to handle obstacles, such as finding an alternative path
// or waiting for a short duration before retrying navigation
// Trigger attack animation
TriggerAttackAnimation(): void =
// Implement logic to play attack animation
// Apply damage to player
ApplyDamageToPlayer(): void =
// Implement logic to apply damage to the player character
// Get the player character
GetPlayerCharacter(): fort_character =
// Implement logic to retrieve the player character
return fort_character{}
Explanation:
State Machine Implementation: The NPC operates in three states: Idle, Chase, and Attack. It transitions between these states based on the player's proximity.
Idle State: The NPC remains stationary until the player enters the detection radius, prompting a transition to the Chase state.
Chase State: The NPC navigates towards the player at a slow speed. If the player moves within attack range, the NPC transitions to the Attack state.
Attack State: The NPC performs a melee attack if the attack cooldown has elapsed. If the player moves out of attack range, the NPC returns to the Chase state.
Navigation: The NavigateToPlayer function uses the NavigateTo method to move the NPC towards the player, handling obstacles effectively.
Animations: The TriggerAttackAnimation function is a placeholder for triggering attack animations defined in the blueprint.
By implementing this state machine and ensuring the NPC can navigate around obstacles, you create a melee enemy that is both challenging and enjoyable to fight against.