Class: RGame::Engine::Components::ThrustController
- Inherits:
-
RGame::Engine::Component
- Object
- RGame::Engine::Component
- RGame::Engine::Components::ThrustController
- Defined in:
- lib/rgame/engine/components/thrust_controller.rb
Overview
Inertial "ship" flight on top of a Velocity sibling: a turn axis rotates the
node (angular velocity) and a thrust axis accelerates it along its heading,
with optional drag and a top-speed clamp. Reads intent in control and
integrates it in update, so it composes with the normal phase order.
Heading convention: angle 0 points along +x ("right"), so forward is (cos θ, sin θ) — consistent with the renderer's clockwise rotation under a y-down screen (e.g. +90° faces down). Firing is intentionally NOT here — see ActionTrigger + the owning node, which knows its muzzle geometry.
Instance Attribute Summary
Attributes inherited from RGame::Engine::Component
Instance Method Summary collapse
- #control(actions) ⇒ Object
-
#initialize(turn_speed:, accel:, max_speed:, drag: 0.0, turn_action: :turn, thrust_action: :thrust) ⇒ ThrustController
constructor
A new instance of ThrustController.
-
#on_attach ⇒ Object
The Velocity sibling is only guaranteed present once attached to a node.
- #update(dt) ⇒ Object
Methods inherited from RGame::Engine::Component
#context, #draw, #on_detach, #sweep_freed
Methods included from Signal::DSL
Constructor Details
#initialize(turn_speed:, accel:, max_speed:, drag: 0.0, turn_action: :turn, thrust_action: :thrust) ⇒ ThrustController
Returns a new instance of ThrustController.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rgame/engine/components/thrust_controller.rb', line 16 def initialize(turn_speed:, accel:, max_speed:, drag: 0.0, turn_action: :turn, thrust_action: :thrust) super() @turn_speed = turn_speed @accel = accel @max_speed = max_speed @drag = drag @turn_action = turn_action @thrust_action = thrust_action @thrust = 0.0 end |
Instance Method Details
#control(actions) ⇒ Object
31 32 33 34 |
# File 'lib/rgame/engine/components/thrust_controller.rb', line 31 def control(actions) @velocity.spin = actions.axis(@turn_action) * @turn_speed @thrust = actions.axis(@thrust_action) end |
#on_attach ⇒ Object
The Velocity sibling is only guaranteed present once attached to a node.
29 |
# File 'lib/rgame/engine/components/thrust_controller.rb', line 29 def on_attach = @velocity = node.get_component(Velocity) |
#update(dt) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/rgame/engine/components/thrust_controller.rb', line 36 def update(dt) if @thrust != 0.0 @velocity.vx += Math.cos(node.angle) * @accel * @thrust * dt @velocity.vy += Math.sin(node.angle) * @accel * @thrust * dt end apply_drag(dt) if @drag.positive? clamp_speed end |