SCRIPTING API / Multiplayer / Bot
Bot
Drives server bots (players added with GameSession.AddBot). A bot applies its input every server tick through the same networked character step as client players, so it collides with the level and replicates like them. Its behaviour is game code: a GameMode or a bot class decides the input.
Kindclass
NamespaceKroys.EngineScripting
Members5
Source
GameSession.csEXAMPLE
In a script
A complete script that uses Bot; copy it into your scripts project.
Multiplayer.cs
public sealed class ChaseBots : GameMode { private readonly List<Vector3> path = new(); protected override void OnStart() { GameSession.AddBot("Hunter"); } protected override void OnFixedUpdate(float fixedDeltaTime) { Player? target = GameSession.Players.FirstOrDefault(p => !p.IsBot); foreach (Player bot in GameSession.Players.Where(p => p.IsBot)) { if (target is not Player human) { Bot.Stop(bot); continue; } Vector3 from = bot.Entity.Transform.WorldPosition; Vector3 to = human.Entity.Transform.WorldPosition; // With a baked navmesh, walk the path's corners; without one, head straight there. Vector3 next = to; if (Navigation.IsReady && Navigation.FindPath(from, to, path) != NavPathStatus.Failed && path.Count > 1) next = path[1]; Bot.MoveToward(bot, next, arriveDistance: 1.0f, sprint: Vector3.Distance(from, to) > 8.0f); } } }
REFERENCE
Members
Methods
#public static bool SetInput(Player bot, Vector2 move, float yawDegrees, bool jump = false, bool sprint = false)Sets the input the bot applies every tick until changed: move axes relative to its facing (x right, y forward, each -1..1), its absolute world yaw in degrees (0 faces -Z), jump and sprint.
#public static bool Stop(Player bot)Stops the bot (no move, keeps its facing).
#public static bool MoveToward(Player bot, Vector3 target, float arriveDistance = 0.5f, bool sprint = false)Walks the bot toward a world point (turns to face it and moves forward). Returns false when it is within
arriveDistance (then it stops).#public static float YawToward(Vector3 direction)World yaw in degrees that faces a horizontal direction (0 faces -Z).
#public static float YawOf(Player bot)Current world yaw of the bot's character in degrees.
Signatures
public static bool SetInput(Player bot, Vector2 move, float yawDegrees, bool jump = false, bool sprint = false) public static bool Stop(Player bot) public static bool MoveToward(Player bot, Vector3 target, float arriveDistance = 0.5f, bool sprint = false) public static float YawToward(Vector3 direction) public static float YawOf(Player bot)
KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.