OutwardLightStudio/nexus

Add Rotation Support to Moving Hazard Component

Closed this issue · 1 comments

Add Rotation Support to Moving Hazard Component

Current Behavior

Using a tween animation, the MovingHazard node currently supports linear movement between two points. The hazard moves from its origin position to a specified destination and back in a looping pattern. The movement works correctly, but the hazard cannot rotate during its journey.

Desired Behavior

The MovingHazard should support both position and rotation tweening. As the hazard moves from its origin to the destination point, it should simultaneously rotate to a specified rotation value and then return to both its original position and rotation. Both the position and rotation animations should be synchronized and smooth.

Hazard Movement and Rotation System Specification

Overview

The hazard movement and rotation system provides configurable animations for hazardous objects in the game environment. This system enables level designers to create interactive hazards with customizable movement patterns and rotations while preserving their initial placement and orientation.

Purpose

The system serves three primary use cases for level designers:

Creating hazards that rotate in place, implementing hazards that translate between two positions, and developing hazards that combine both translation and rotation.

Technical Architecture

Core Component

The system extends the AnimatableBody3D class, providing a robust foundation for physical interactions while maintaining precise control over movement and rotation animations.

Configuration Parameters

desired_destination: Vector3

This optional parameter defines the target position for the hazard's movement.

  • Default value: Vector3.ZERO
  • When non-zero: The hazard moves between its initial position and this destination
  • When zero: The hazard maintains its initial position
  • Implementation note: Position is relative to the object's initial placement

desired_rotation: Vector3

This optional parameter defines the target rotation in degrees.

  • Default value: Vector3.ZERO
  • When non-zero: The hazard rotates between its initial rotation and this target
  • When zero: The hazard maintains its initial rotation
  • Implementation note: Rotation is relative to the object's initial orientation

desired_duration: float

This parameter controls the timing of the complete animation cycle.

  • Default value: 1.0 seconds
  • Scope: Applies uniformly to both movement and rotation animations
  • Purpose: Ensures synchronized timing between all active animations
  • Note: Duration applies to each phase (forward and return) independently

Animation Implementation

Initialization

  • System captures initial position and rotation on startup
  • All animations are configured relative to these initial values
  • Level designer's setup is preserved as the base state

Animation Control

The system utilizes Godot's tween system with the following specifications:

Phase 1 - Forward Movement:

  • Parallel tweens handle simultaneous position and rotation changes
  • Movement from initial to target position (if desired_destination != Vector3.ZERO)
  • Rotation from initial to target angles (if desired_rotation != Vector3.ZERO)
  • TRANS_SINE transition type provides natural motion

Phase 2 - Return Movement:

  • Chained after Phase 1 using tween.chain()
  • Parallel tweens handle simultaneous position and rotation changes
  • Movement back to initial position (if desired_destination != Vector3.ZERO)
  • Rotation back to initial angles (if desired_rotation != Vector3.ZERO)
  • Maintains same duration and transition type as Phase 1

The complete cycle loops infinitely, maintaining continuous operation.

Behavior Modes

Stationary Rotation

Activated when only desired_rotation is non-zero:

  • Object rotates around its axis at the initial position
  • Maintains original placement in the level
  • Rotation alternates between initial and target angles

Pure Translation

Activated when only desired_destination is non-zero:

  • Object moves between initial position and target destination
  • Maintains its initial rotation throughout the movement
  • Movement follows a smooth, sine-based interpolation

Combined Movement

Activated when both rotation and destination are non-zero:

  • Synchronizes rotation and positional movement
  • Maintains timing consistency between both animations
  • Creates complex, coordinated hazard patterns

Error Handling

The system includes protection against:

  • Implicit boolean conversion errors through explicit Vector3.ZERO comparisons
  • Proper animation sequencing through explicit phase chaining
  • Coordinate system inconsistencies through relative transformations
  • Runtime configuration changes through initialization capture

Level Designer Guidelines

Best Practices

  1. Set initial placement and rotation in the editor first
  2. Configure desired_destination relative to initial position
  3. Set desired_rotation relative to initial rotation
  4. Adjust desired_duration to match gameplay requirements
  5. Test with non-zero values for intended transformations

Common Configurations

  1. Rotating Platform:

    • Set desired_rotation only
    • Leave desired_destination at default
  2. Moving Platform:

    • Set desired_destination only
    • Leave desired_rotation at default
  3. Complex Hazard:

    • Configure both desired_destination and desired_rotation
    • Ensure desired_duration provides appropriate challenge level

Future Considerations

Potential Enhancements

  1. Additional easing function options
  2. Variable speed profiles
  3. Multiple waypoint support
  4. Runtime parameter modification
  5. Event trigger system integration

Maintenance Notes

  • Regular testing with physics interactions
  • Performance monitoring for multiple instances
  • Compatibility verification with new engine versions

This task is surprisingly difficult.