Enemy movement TDS module


creatorStore

:red_question_mark: Why u should use it?

Includes replication optimization, smooth rotation, and flexible movement control

:warning: Note

The system is unable to calculate elevation changes (tried using shapeCast)

:star: Example of code

local EnemyController = require(ReplicatedStorage.EnemyController)

local enemy = EnemyController.new(
  model, -- source model from ReplicatedStorage
  Vector3.zero -- start position
)

-- Move to point
enemy:MoveTo(Vector3.new(10, 0, 5))

-- Move on path
enemy:MoveOnPath({
  Vector3.new(10, 0, 0),
  Vector3.new(10, 0, 10),
  Vector3.new(0, 0, 10)
})

:bookmark_tabs: API

Read the API
function MoveTo(location: Vector3, callback: (() -> ())?)

Moves enemy to the specified location over time using current walk speed.

Parameters:

  • location: Vector3
    The target position to move to
  • callback: (() → ())?
    Optional function called when path is completed

function MoveOnPath(path: {Vector3}, callback: (() -> ())?)

Moves enemy through a series of waypoints sequentially.

Parameters:

  • path: {Vector3}
    Array of Vector3 waypoints to follow in order
  • callback: (() → ())?
    Optional function called when entire path is completed

function Position(): Vector3

Returns the absolute enemy position

Returns:

  • Vector3 - Absolute position

function Stane(location: Vector3?)

Stops movement and optionally teleports enemy to specified location.

Parameters:

  • location: Vector3?
    Optional teleport destination (uses current position if nil)

function Damage(amount: number)

Applies damage to the enemy and triggers health events.

Parameters:

  • amount: number
    Damage amount to subtract from current health

function SetWalkSpeed(speed: number)

Changes movement speed dynamically(even during active movement).

Parameters:

  • speed: number
    New movement speed in studs/second

function Destroy()

Completely removes the enemy and cleans up all resources.

Events

  • event MoveFinished: Signal<>
    Fired when the enemy completes movement to a single point.

  • event HealthChanged: Signal
    Fired when health changes,providing the new health value.

  • event Destroying: Signal<>
    Fired right before the enemy is destroyed for cleanup operations.

5 Likes

Update v 0.2.0

  • Now only one RemoteSignal is used for route movement
  • New PathFinished event

(Recv ≈ 1.0)

Also here is how :Position() works

1 Like

I have a really good idea
I saw a YouTube video before where he made a loop for NPCs that had to go to certain places and then go to certain places again
It actually worked like this
part1
part2
part3
part4
and there was no need for Vector3 and this was the best thing I had ever seen
and I think you should do the same
because the parts change, even the enemy’s path may change in a game

you could just copy paste the vector3s from the parts.. it’s better to loop through a table than an instance’s children.

Patch v 0.2.1

  • The callback parameter is supported again in the MoveTo and MoveOnPath methods

Next Features

  • BeginDamage and EndDamage methods

parts are significantly easier to move lol