Skip to content

Commit

Permalink
Add "turn backwards" to relative control scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jun 28, 2024
1 parent 2387028 commit c13671c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ turn_right={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
turn_backwards={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
fire={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
Expand Down
14 changes: 11 additions & 3 deletions ships/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,26 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:

match UserPreferences.control_scheme:
UserPreferences.ControlScheme.RELATIVE:
if not Input.is_action_pressed("turn_left") and not Input.is_action_pressed("turn_right"):
var turning_left := Input.is_action_pressed("turn_left")
var turning_right := Input.is_action_pressed("turn_right")
var turning_backwards = Input.is_action_pressed("turn_backwards")
if not turning_left and not turning_right and not turning_backwards:
return

if not self.consume_turning_energy(state.get_step()):
return

if Input.is_action_pressed("turn_left"):
if turning_left:
state.angular_velocity = Vector3.ZERO
state.transform.basis = state.transform.basis.rotated(Vector3.DOWN, -self.ship_def.torque * state.get_step())
if Input.is_action_pressed("turn_right"):
if turning_right:
state.angular_velocity = Vector3.ZERO
state.transform.basis = state.transform.basis.rotated(Vector3.DOWN, self.ship_def.torque * state.get_step())
if turning_backwards:
var desired_basis = Basis.looking_at( - self.linear_velocity.normalized())

state.angular_velocity = Vector3.ZERO
state.transform.basis = state.transform.basis.slerp(desired_basis, self.ship_def.torque * state.get_step())

UserPreferences.ControlScheme.ABSOLUTE:
var desired_direction := self._absolute_input_direction()
Expand Down

0 comments on commit c13671c

Please sign in to comment.