add controller support and deifting :3
This commit is contained in:
parent
10ce3d6e83
commit
977fccc449
4 changed files with 32 additions and 17 deletions
|
@ -38,13 +38,14 @@ sources/1 = SubResource("TileSetAtlasSource_8fd31")
|
|||
|
||||
[sub_resource type="Environment" id="Environment_iwcc3"]
|
||||
background_mode = 3
|
||||
glow_enabled = true
|
||||
glow_levels/1 = 1.0
|
||||
glow_levels/2 = 0.5
|
||||
glow_levels/3 = 0.3
|
||||
glow_levels/4 = 0.1
|
||||
glow_levels/5 = 0.0
|
||||
glow_levels/7 = 1.0
|
||||
glow_bloom = 0.1
|
||||
glow_bloom = 0.05
|
||||
glow_blend_mode = 1
|
||||
|
||||
[node name="main" type="Node2D"]
|
||||
|
|
|
@ -2,15 +2,26 @@ extends RigidBody2D
|
|||
class_name Player
|
||||
|
||||
@export var thruster_strength := 40.0
|
||||
@export var rotation_strnegth := 500.0
|
||||
@export var rotation_strength := 10.0
|
||||
|
||||
@export var drift_curve : Curve
|
||||
|
||||
var angular_velocity_target := 0.0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var input := Vector2(Input.get_action_strength("left") - Input.get_action_strength("right"), Input.get_action_strength("front") - Input.get_action_strength("back"))
|
||||
var input := Vector2(Input.get_action_strength("right") - Input.get_action_strength("left"), Input.get_action_strength("boost"))
|
||||
|
||||
apply_central_impulse(Vector2.DOWN.rotated(rotation) * thruster_strength * delta * input.y)
|
||||
apply_torque_impulse(input.x * rotation_strnegth * delta)
|
||||
var angle = abs(linear_velocity.angle_to(Vector2.UP.rotated(rotation)))
|
||||
# var drift_factor = clamp(5-abs(linear_velocity.dot(Vector2.UP.rotated(rotation))), 1, 5)
|
||||
var drift_factor = 2.0 * drift_curve.sample_baked(angle / PI) + 1.0
|
||||
apply_central_impulse(Vector2.UP.rotated(rotation) * thruster_strength * delta * input.y * drift_factor)
|
||||
|
||||
if input.y < 0:
|
||||
angular_velocity_target = input.x * rotation_strength
|
||||
|
||||
if input.y > 0:
|
||||
%thruster.active = true
|
||||
else:
|
||||
%thruster.active = false
|
||||
|
||||
func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
|
||||
state.angular_velocity = lerp(state.angular_velocity, angular_velocity_target, 0.1)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=10 format=3 uid="uid://b3xadpl4pu33u"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://b3xadpl4pu33u"]
|
||||
|
||||
[ext_resource type="Script" path="res://player/player.gd" id="1_kkw55"]
|
||||
[ext_resource type="Texture2D" uid="uid://dlenptyfk1iwn" path="res://player/ship.png" id="2_1h4u8"]
|
||||
|
@ -7,6 +7,10 @@
|
|||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_6481p"]
|
||||
friction = 0.0
|
||||
|
||||
[sub_resource type="Curve" id="Curve_f6djc"]
|
||||
_data = [Vector2(0.2, 0), 0.0, 0.0, 0, 0, Vector2(0.5, 1), 0.0, 0.0, 0, 0, Vector2(1, 0.505618), 0.0, 0.0, 0, 0]
|
||||
point_count = 3
|
||||
|
||||
[sub_resource type="Curve" id="Curve_f2yms"]
|
||||
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.217391, 1), 0.0, 0.0, 0, 0, Vector2(0.804348, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||
point_count = 4
|
||||
|
@ -42,6 +46,7 @@ gravity_scale = 0.0
|
|||
can_sleep = false
|
||||
angular_damp = 2.0
|
||||
script = ExtResource("1_kkw55")
|
||||
drift_curve = SubResource("Curve_f6djc")
|
||||
|
||||
[node name="camera" type="Camera2D" parent="."]
|
||||
zoom = Vector2(4, 4)
|
||||
|
|
|
@ -23,24 +23,22 @@ window/stretch/aspect="keep_width"
|
|||
|
||||
[input]
|
||||
|
||||
back={
|
||||
boost={
|
||||
"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)
|
||||
]
|
||||
}
|
||||
front={
|
||||
"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(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
|
||||
]
|
||||
}
|
||||
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":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
||||
"deadzone": 0.1,
|
||||
"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(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
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":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
|
||||
"deadzone": 0.1,
|
||||
"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(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue