From: Eduardo Date: Fri, 9 Feb 2024 21:48:47 +0000 (+0100) Subject: run & squat base interactions (with shift and L-alt) X-Git-Url: http://git.edufdez.es/?a=commitdiff_plain;h=a09bf49ca2b2fa99eda7f50adb860a98e8b9bca2;p=ScaryGame.git run & squat base interactions (with shift and L-alt) --- diff --git a/levels/unicorn_level/unicorn_map.tscn b/levels/unicorn_level/unicorn_map.tscn index b2c2039..8216467 100644 --- a/levels/unicorn_level/unicorn_map.tscn +++ b/levels/unicorn_level/unicorn_map.tscn @@ -1796,9 +1796,8 @@ transform = Transform3D(-2.18557e-08, 0, 0.5, 0, 0.5, 0, -0.5, 0, -2.18557e-08, [node name="CameraPivot" type="Marker3D" parent="."] transform = Transform3D(1, 0, 3.72529e-09, 0, 1, 0, 7.45058e-09, 0, 1, 0, 2.17843, 0) -[node name="Player" parent="." node_paths=PackedStringArray("pivot") instance=ExtResource("1_yhk1e")] +[node name="Player" parent="." instance=ExtResource("1_yhk1e")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -143.826, 0, -132.995) -pivot = NodePath("Pivot") [node name="BaseEnemy" parent="." node_paths=PackedStringArray("player") instance=ExtResource("6_os3o0")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -229.93, 0, -72.7142) diff --git a/player/Player.gd b/player/Player.gd index 16ca9a1..6908a9d 100644 --- a/player/Player.gd +++ b/player/Player.gd @@ -1,18 +1,47 @@ extends CharacterBody3D +@export_category("Noise") +@export_range(0, 2) var squating_noise_mod: float = 1 +@export_range(0, 2) var running_noise_mod: float = 1 +@export_category("Movement") # How fast the player moves in meters per second. @export var speed := 5 +@export_range(0, 2) var squating_speed_mod: float = .5 +@export_range(0, 2) var runnig_speed_mod: float = 1.5 # The downward acceleration when in the air, in meters per second squared. @export var fall_acceleration := 10 -@export var pivot: Node3D + +@onready var pivot := $Pivot +@onready var camera := $Camera3D var target_velocity := Vector3.ZERO var noise: int = 0 +const squat_position := 0.6 # Position to which the camera moves when squatting +const stand_position := 1.7 # Position to which the camera moves when standing +const move_speed := 8.0 # Speed at which the camera moves from stand to squat and back +var is_squatting := false + # Called every frame. 'delta' is the elapsed time since the previous frame. -func _physics_process(_delta): +func _physics_process(delta): var direction := Vector3.ZERO + var speed_mod: float = 1 + + if Input.is_action_just_pressed("squat"): + is_squatting = true + elif Input.is_action_just_released("squat"): + is_squatting = false + + if is_squatting and camera.position.y > squat_position: + camera.translate(Vector3(0, -move_speed * delta, 0)) + elif not is_squatting and camera.position.y < stand_position: + camera.translate(Vector3(0, move_speed * delta, 0)) + + if Input.is_action_pressed("run"): + speed_mod = runnig_speed_mod + if Input.is_action_pressed("squat"): + speed_mod = squating_speed_mod if Input.is_action_pressed("move_right"): direction += transform.basis.x @@ -32,8 +61,8 @@ func _physics_process(_delta): noise = clamp(noise + 1, 0, 9) set_meta("noise", noise) - target_velocity.x = direction.x * speed - target_velocity.z = direction.z * speed + target_velocity.x = direction.x * speed * speed_mod + target_velocity.z = direction.z * speed * speed_mod # if not is_on_floor(): # target_velocity.y = target_velocity.y - (fall_acceleration * delta) diff --git a/player/Player.tscn b/player/Player.tscn index a805ecd..9b5bea9 100644 --- a/player/Player.tscn +++ b/player/Player.tscn @@ -13,10 +13,9 @@ volumetric_fog_albedo = Color(0.144063, 0.144063, 0.144063, 1) radius = 0.25 height = 1.8 -[node name="CharacterBody3D" type="CharacterBody3D" node_paths=PackedStringArray("pivot") groups=["player"]] +[node name="CharacterBody3D" type="CharacterBody3D" groups=["player"]] top_level = true script = ExtResource("1_x0wva") -pivot = NodePath("Pivot") metadata/noise = 0.0 [node name="Timer" type="Timer" parent="."] diff --git a/project.godot b/project.godot index 3a9e8c4..a496a1e 100644 --- a/project.godot +++ b/project.godot @@ -90,3 +90,13 @@ left_click={ "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(143, 25),"global_position":Vector2(147, 66),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) ] } +run={ +"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":4194325,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +squat={ +"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":4194328,"key_label":0,"unicode":0,"echo":false,"script":null) +] +}