Skip to content

Commit

Permalink
velocity helper now can receive the calculated velocity lenght and cr…
Browse files Browse the repository at this point in the history
…eated input actions to move vehicles
  • Loading branch information
ninetailsrabbit committed Dec 20, 2024
1 parent f982119 commit 28af922
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
7 changes: 6 additions & 1 deletion autoload/persistence/settings/input_controls.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ const ItemLeft: StringName = &"item_left"
const ItemRight: StringName = &"item_right"
const ToggleInventory: StringName = &"toggle_inventory"


const Drag: StringName = &"drag"

const VehicleAccelerate: StringName = &"vehicle_accelerate"
const VehicleReverseAccelerate: StringName = &"vehicle_reverse_accelerate"
const VehicleSteerRight: StringName = &"vehicle_steer_right"
const VehicleSteerLeft: StringName = &"vehicle_steer_left"
const VehicleHandBrake: StringName = &"vehicle_hand_brake"

const PerformanceMetrics: StringName = &"performance_metrics"
const PauseGame: StringName = &"pause"
34 changes: 34 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,40 @@ item_right={
, 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,"location":0,"echo":false,"script":null)
]
}
vehicle_accelerate={
"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":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
, 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":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":5,"axis_value":1.0,"script":null)
]
}
vehicle_reverse_accelerate={
"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":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
, 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,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":false,"script":null)
]
}
vehicle_hand_brake={
"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,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":4,"axis_value":1.0,"script":null)
]
}
vehicle_steer_right={
"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":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
, 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,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
]
}
vehicle_steer_left={
"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":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
, 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":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
]
}

[internationalization]

Expand Down
5 changes: 4 additions & 1 deletion utilities/math/math_helper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ const ErdosBorweinConstant: float = 1.6066951524 # ERDOS-BORWEIN CONSTANT, norm
const NivensConstant: float = 1.7052111401 # NIVENS' CONSTANT, number theory
const UniversalParabolicConstant: float = 2.2955871493 # UNIVERSAL PARABOLIC CONSTANT, reflection coefficient
const SierpinskisConstant: float = 2.5849817595 # SIERPINSKI'S CONSTANT, Sierpinski triangle fractal

const FransenRobinsonConstant: float = 2.807770

const MetersPerSecondToMilePerHourFactor: float = 2.23694
const MetersPerSecondToKilometersPerHourFactor: float = 3.6

const HexCharacters: String = "0123456789ABCDEF"

## "x": This is the input value between 0 and 1 that you want to apply the bias to.
Expand Down
15 changes: 8 additions & 7 deletions utilities/motion/velocity_helper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ enum SpeedUnit {
MilesPerHour,
}

const MetersPerSecondToMilePerHourFactor: float = 2.23694
const MetersPerSecondToKilometersPerHourFactor: float = 3.6


static func current_speed_on(speed_unit: SpeedUnit, velocity) -> float:
match speed_unit:
Expand All @@ -21,18 +18,22 @@ static func current_speed_on(speed_unit: SpeedUnit, velocity) -> float:

static func current_speed_on_miles_per_hour(velocity) -> float:
if velocity is Vector2:
return roundf(velocity.length() * MetersPerSecondToMilePerHourFactor)
return roundf(velocity.length() * MathHelper.MetersPerSecondToMilePerHourFactor)
elif velocity is Vector3:
return roundf(Vector3(velocity.x, 0, velocity.z).length() * MetersPerSecondToMilePerHourFactor)
return roundf(Vector3(velocity.x, 0, velocity.z).length() * MathHelper.MetersPerSecondToMilePerHourFactor)
elif velocity is float: ## We assume we received the velocity length
return roundf(velocity * MathHelper.MetersPerSecondToMilePerHourFactor)
else:
return 0.0


static func current_speed_on_kilometers_per_hour(velocity) -> float:
if velocity is Vector2:
return roundf(velocity.length() * MetersPerSecondToKilometersPerHourFactor)
return roundf(velocity.length() * MathHelper.MetersPerSecondToKilometersPerHourFactor)
elif velocity is Vector3:
return roundf(Vector3(velocity.x, 0, velocity.z).length() * MetersPerSecondToKilometersPerHourFactor)
return roundf(Vector3(velocity.x, 0, velocity.z).length() * MathHelper.MetersPerSecondToKilometersPerHourFactor)
elif velocity is float: ## We assume we received the velocity length
return roundf(velocity * MathHelper.MetersPerSecondToKilometersPerHourFactor)
else:
return 0.0

Expand Down

0 comments on commit 28af922

Please sign in to comment.