Went to driving school
This commit is contained in:
parent
5924215f3c
commit
cf0fbfa45f
3 changed files with 29 additions and 14 deletions
|
@ -38,9 +38,9 @@ accelerate={
|
||||||
}
|
}
|
||||||
brake={
|
brake={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"echo":false,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":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":83,"key_label":0,"unicode":115,"echo":false,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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)
|
, 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)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
left={
|
left={
|
||||||
|
@ -55,3 +55,9 @@ 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":68,"key_label":0,"unicode":100,"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":68,"key_label":0,"unicode":100,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
reverse={
|
||||||
|
"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,"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,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
@ -8,13 +8,9 @@ size = Vector2(36, 20)
|
||||||
|
|
||||||
[node name="player" type="StaticBody2D" node_paths=PackedStringArray("camera")]
|
[node name="player" type="StaticBody2D" node_paths=PackedStringArray("camera")]
|
||||||
script = ExtResource("1_g4ij8")
|
script = ExtResource("1_g4ij8")
|
||||||
acc = 600.0
|
|
||||||
dec = 400.0
|
|
||||||
max_speed = 3000.0
|
|
||||||
turn_speed = 0.8
|
turn_speed = 0.8
|
||||||
brake_strength = 600.0
|
brake_strength = 600.0
|
||||||
drift_factor = 1.2
|
drift_factor = 1.2
|
||||||
camera_offset_factor = 0.5
|
|
||||||
camera = NodePath("Camera2D")
|
camera = NodePath("Camera2D")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
|
@ -30,6 +26,5 @@ shape = SubResource("RectangleShape2D_w2nj7")
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
rotation = 1.5708
|
rotation = 1.5708
|
||||||
ignore_rotation = false
|
ignore_rotation = false
|
||||||
position_smoothing_enabled = true
|
|
||||||
rotation_smoothing_enabled = true
|
rotation_smoothing_enabled = true
|
||||||
rotation_smoothing_speed = 10.0
|
rotation_smoothing_speed = 10.0
|
||||||
|
|
|
@ -1,25 +1,30 @@
|
||||||
extends StaticBody2D
|
extends StaticBody2D
|
||||||
# constants
|
# constants
|
||||||
## acceleration of the car while holding the accelerate button
|
## acceleration of the car while holding the accelerate button
|
||||||
@export var acc := 20.
|
@export var acc := 600.
|
||||||
|
## acceleration of the car while driving backwards
|
||||||
|
@export var rev := 500.
|
||||||
## natural deceleration of the car
|
## natural deceleration of the car
|
||||||
@export var dec := 4.
|
@export var dec := 400.
|
||||||
## maximum speed of the car
|
## maximum speed of the car
|
||||||
@export var max_speed := 100.
|
@export var max_speed := 1200.
|
||||||
|
## maximum speed of the car while driving backwards
|
||||||
|
@export var max_reverse := 500.
|
||||||
## how many radians the car turns per second, higher value -> faster turns
|
## how many radians the car turns per second, higher value -> faster turns
|
||||||
@export var turn_speed := 1.
|
@export var turn_speed := 1.
|
||||||
## affects how fast the brakes, higher value -> quicker to stand still
|
## affects how fast the brakes, higher value -> quicker to stand still
|
||||||
@export var brake_strength := 30.
|
@export var brake_strength := 30.
|
||||||
## regulates how much more you can turn while breaking, values below 1 mean you can turn worse while drifting
|
## regulates how much more you can turn while breaking, values below 1 mean you can turn worse while drifting
|
||||||
@export var drift_factor := 1.5
|
@export var drift_factor := 1.5
|
||||||
## regulates how far the camera looks ahead of the player (affected by speed)
|
## maximum number of pixels how far the camera looks ahead of the player (affected by speed)
|
||||||
@export var camera_offset_factor = .2
|
@export var camera_offset = 400.
|
||||||
|
|
||||||
# references
|
# references
|
||||||
@export var camera : Camera2D
|
@export var camera : Camera2D
|
||||||
|
|
||||||
# variables
|
# variables
|
||||||
var momentum: Vector2
|
var momentum: Vector2
|
||||||
|
#var direction = 0 # 1 for forward, 0 for standing still, -1 for reverse
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
@ -30,6 +35,7 @@ func _ready():
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var acc_d = acc * delta
|
var acc_d = acc * delta
|
||||||
var dec_d = dec * delta
|
var dec_d = dec * delta
|
||||||
|
var rev_d = rev * delta
|
||||||
var turn_d = turn_speed * delta
|
var turn_d = turn_speed * delta
|
||||||
var brake_d = brake_strength * delta
|
var brake_d = brake_strength * delta
|
||||||
var turn_factor = 1
|
var turn_factor = 1
|
||||||
|
@ -42,6 +48,11 @@ func _process(delta):
|
||||||
if Input.is_action_pressed("accelerate"):
|
if Input.is_action_pressed("accelerate"):
|
||||||
momentum += acc_d * Vector2(1,0).rotated(rotation)
|
momentum += acc_d * Vector2(1,0).rotated(rotation)
|
||||||
|
|
||||||
|
# if Input.is_action_pressed("reverse"):
|
||||||
|
# print_debug("reverse vector: ", rev_d * Vector2(-1,0).rotated(rotation))
|
||||||
|
# momentum += rev_d * Vector2(-1,0).rotated(rotation)
|
||||||
|
# print_debug("momentum vector = ", momentum)
|
||||||
|
|
||||||
if Input.is_action_pressed("brake"):
|
if Input.is_action_pressed("brake"):
|
||||||
turn_factor = drift_factor
|
turn_factor = drift_factor
|
||||||
if momentum.length() > brake_d:
|
if momentum.length() > brake_d:
|
||||||
|
@ -53,8 +64,11 @@ func _process(delta):
|
||||||
rotate(turn_d*turn_factor*-1)
|
rotate(turn_d*turn_factor*-1)
|
||||||
if Input.is_action_pressed("right"):
|
if Input.is_action_pressed("right"):
|
||||||
rotate(turn_d*turn_factor)
|
rotate(turn_d*turn_factor)
|
||||||
|
|
||||||
|
if !Input.is_action_pressed("brake"):
|
||||||
|
momentum = Vector2(1,0).rotated(rotation) * momentum.length()
|
||||||
|
|
||||||
camera.position = Vector2(momentum.length() * camera_offset_factor, 0)
|
camera.position = Vector2((momentum.length() / max_speed) * camera_offset, 0)
|
||||||
camera.rotation_degrees = momentum.angle() + 90
|
camera.rotation_degrees = momentum.angle() + 90
|
||||||
|
|
||||||
if momentum.length() > max_speed:
|
if momentum.length() > max_speed:
|
||||||
|
|
Loading…
Reference in a new issue