Module: Mover
- Included in:
- Actor
- Defined in:
- lib/fantasy/includes/mover.rb
Instance Method Summary collapse
- #add_force(force) ⇒ Object
- #apply_forces(max_speed: Float::INFINITY) ⇒ Object
- #impulse(direction:, force:) ⇒ Object
Instance Method Details
#add_force(force) ⇒ Object
8 9 10 11 |
# File 'lib/fantasy/includes/mover.rb', line 8 def add_force(force) @acceleration ||= Coordinates.zero @acceleration += force end |
#apply_forces(max_speed: Float::INFINITY) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fantasy/includes/mover.rb', line 13 def apply_forces(max_speed: Float::INFINITY) @acceleration ||= Coordinates.zero @velocity ||= Coordinates.zero @velocity += @acceleration @velocity.resize(max_speed) if @velocity.length > max_speed unless @velocity.length.zero? @position += @velocity * Global.frame_time end @acceleration = Coordinates.zero end |
#impulse(direction:, force:) ⇒ Object
4 5 6 |
# File 'lib/fantasy/includes/mover.rb', line 4 def impulse(direction:, force:) add_force(direction.normalize * force) end |