diff options
-rw-r--r-- | prefabs/test_arena.tscn | 7 | ||||
-rw-r--r-- | scripts/player.gd | 20 |
2 files changed, 18 insertions, 9 deletions
diff --git a/prefabs/test_arena.tscn b/prefabs/test_arena.tscn index cccb951..87d6463 100644 --- a/prefabs/test_arena.tscn +++ b/prefabs/test_arena.tscn @@ -7,8 +7,8 @@ [sub_resource type="Environment" id="Environment_2poci"] background_color = Color(0.130548, 0.170599, 0.433834, 1) ambient_light_source = 2 -ambient_light_color = Color(0.244776, 0.244776, 0.244776, 1) -ambient_light_energy = 2.27 +ambient_light_color = Color(1, 1, 1, 1) +ambient_light_energy = 0.6 [sub_resource type="BoxMesh" id="BoxMesh_ox60m"] size = Vector3(0.1, 0.1, 0.5) @@ -77,9 +77,6 @@ script = ExtResource("1_dbsm0") [node name="Node3D" type="WorldEnvironment" parent="."] environment = SubResource("Environment_2poci") -[node name="OmniLight3D" type="DirectionalLight3D" parent="."] -transform = Transform3D(0.838671, -0.296632, 0.456773, 0, 0.838671, 0.544639, -0.544639, -0.456773, 0.703368, 0, 0, -0.0795405) - [node name="Player" parent="." node_paths=PackedStringArray("HEAD", "HEADBOB_ANIMATION") instance=ExtResource("1_vc6b5")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3, 0, 3) HEAD = NodePath("PlayerCam") diff --git a/scripts/player.gd b/scripts/player.gd index f476bf0..275100a 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -4,6 +4,8 @@ extends Node3D @export var grapple_speed: float = 10 @export var fire_distance: float = 100 +@export var fire_rate: float = 0.1 + enum State { NO_GRAPPLE, FREE, @@ -15,6 +17,9 @@ var grapple_target: Vector3 = Vector3.ZERO var bullet_inst = preload("res://prefabs/bullet.tscn") +var ammo: int = 100 +var fire_timer: float = fire_rate + # Called when the node enters the scene tree for the first time. func _ready() -> void: pass # Replace with function body. @@ -44,8 +49,8 @@ func do_grapple() -> void: get_parent().local_velocity = dir_to_target * grapple_speed -func fire_weapon() -> void: - if Input.is_action_just_pressed("attack"): +func fire_weapon(delta: float) -> void: + if Input.is_action_pressed("attack") and ammo > 0 and fire_timer >= fire_rate: var space_state = get_world_3d().direct_space_state var starting_pos = global_position var ending_pos = starting_pos + fire_distance * -global_transform.basis.z @@ -69,10 +74,17 @@ func fire_weapon() -> void: if abs(global_transform.basis.z.y) > 0.99: up = Vector3(0, 0, 1) bullet.look_at(end, up) + + ammo -= 1 + print("Ammo: ", ammo) + fire_timer = 0 + else: + fire_timer += delta + -func _physics_process(_delta: float) -> void: +func _physics_process(delta: float) -> void: do_grapple() - fire_weapon() + fire_weapon(delta) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta: float) -> void: |