Skip to content

Flying Enemy

Jack X. edited this page Jun 12, 2026 · 7 revisions

Flying Enemy

System Summary

The Flying Enemy is a dynamic enemy type that moves between two points in space, a predictable traversal pattern for the player. Unlike Patrol enemies, Flying Enemies are not constrained to ground navigation and instead move freely in straight-line paths between two defined offsets.

Connected Systems

  • Game Manager (handles reset / state transitions)
  • Property Menu (modifies speed and movement offset)
  • Entity Manager (spawning and saving enemies)
  • Resource System (FlyingPreset .tres files)

Core Behavior

Flying Enemies:

  • Move between two points (Point A and Point B)
  • Reverse direction when reaching either endpoint
  • Use direct velocity-based movement (no pathfinding)
  • Ignore gravity
  • Can collide with level geometry
  • Damage or kill player on contact (via base enemy logic)
  • Can be stomped by player

Feature Breakdown

Base Enemy Behavior (Inherited)

  • Player can defeat enemy by jumping on top of it
  • Player takes damage on side collisions
  • Supports health system
  • Uses shared enemy interface (Enemy.gd)

Flying Enemy Behavior

  • Moves in a straight line between two points:
    • Point A = spawn position
    • Point B = Point A + Offset
  • Automatically switches direction when reaching a point
  • Uses normalized direction vector for smooth motion

Editor Properties

Flying Speed

Controls how fast the enemy travels between points.

  • Higher values = faster movement

Point B Offset

Defines the second movement point relative to the spawn position.

  • X controls horizontal distance
  • Y controls vertical distance
  • Supports diagonal movement

Example:

  • Offset (256, 0) -> moves right
  • Offset (0, -256) -> moves up
  • Offset (256, 256) -> moves diagonally

Important Variables

Runtime Variables

Variable Type Description
propertyFile Resource Stores the currently assigned FlyingPreset resource
point_a Vector2 Spawn position (set when enemy is placed)
point_b Vector2 Calculated endpoint based on offset
target_point Vector2 Current movement destination
speed float Movement speed of the enemy

Important Functions

assign_script(id: String, position: Vector2i) -> void

Assigns a FlyingPreset resource to the enemy based on a generated ID.

Purpose:

  • Loads the correct .tres file from disk
  • Assigns it to propertyFile
  • Sets the enemy's identity in the editor system

apply_script(file: Resource) -> void

Applies a FlyingPreset resource to the enemy instance.

Purpose:

  • Reads stored data from the resource
  • Updates movement behavior based on saved values
  • Recalculates patrol path (Point A and Point B)

Important:

  • Does NOT reposition the enemy in world space
  • Assumes enemy is already placed correctly by the editor

Movement Logic (How It Works)

  1. Enemy spawns at Point A (editor placement)
  2. Point B is calculated using offset: Point B = Point A + Offset
  3. Enemy moves toward target point using normalized direction
  4. When close enough to target:
    • Switches target to the opposite point
    • Repeats indefinitely

Data Flow

  1. Editor places enemy
  2. assign_script()
  3. Resource created/saved (.tres)
  4. apply_script() on load
  5. Point A set = global position
  6. Point B calculated = A + offset
  7. Enemy begins patrol movement

Design Notes

Offset-based system was chosen instead of absolute coordinates to:

  • Make enemy placement reusable
  • Simplify editing in property menu
  • Avoid dependency on world coordinates in resources

Movement is intentionally simple (no pathfinding) to ensure:

  • Predictability for level design
  • Easy debugging
  • Low performance cost

Known Issues

  • Very small offset values result in nearly invisible movement (must ensure slider range is sufficient)
  • May stuck on props if approach at an unusual angle

Summary

The Flying Enemy is a simple but flexible enemy type designed for predictable linear movement. It is fully controlled through a resource-based system and integrates with the editor for real-time configuration.

Clone this wiki locally