Melhoria de codigo do game
This commit is contained in:
@@ -7,8 +7,11 @@ const JUMP_VELOCITY = 10.0
|
||||
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
@export var view : Node3D
|
||||
@export var timer : Timer
|
||||
var movement_velocity : Vector3
|
||||
var rotation_direction : float
|
||||
var can_jump := true
|
||||
var can_timeout := true
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
handle_input(delta)
|
||||
@@ -16,6 +19,13 @@ func _physics_process(delta: float) -> void:
|
||||
jump()
|
||||
handle_animations()
|
||||
|
||||
if is_on_floor():
|
||||
can_jump = true
|
||||
else:
|
||||
if can_timeout:
|
||||
timer.start()
|
||||
can_timeout = false
|
||||
|
||||
var applied_velocity : Vector3
|
||||
applied_velocity = velocity.lerp(movement_velocity, delta * 10)
|
||||
applied_velocity.y = -gravity
|
||||
@@ -55,8 +65,14 @@ func apply_gravity(delta):
|
||||
gravity += 25 * delta
|
||||
|
||||
func jump():
|
||||
if Input.is_action_just_pressed("move_jump") and is_on_floor():
|
||||
if Input.is_action_just_pressed("move_jump") and can_jump:
|
||||
gravity = -JUMP_VELOCITY
|
||||
can_jump = false
|
||||
|
||||
if gravity > 0 and is_on_floor():
|
||||
gravity = 0
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
can_jump = false
|
||||
can_timeout = true
|
||||
|
||||
+27
-1
@@ -1,6 +1,7 @@
|
||||
[gd_scene format=3 uid="uid://d3jfn55lhv658"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bwb5tbqutixgn" path="res://anime_skybox.jpg" id="1_ui7ud"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0qtyhhrmbg6s" path="res://Assets/Models/Prefabs/block_grass.tscn" id="4_v3d7h"]
|
||||
[ext_resource type="PackedScene" uid="uid://dis4m18yyeqww" path="res://Assets/Models/Actors/player.tscn" id="4_ws1nr"]
|
||||
[ext_resource type="Script" uid="uid://ciatq4g0mefhf" path="res://Assets/Scripts/camera_pivot.gd" id="5_vjabh"]
|
||||
|
||||
@@ -46,6 +47,31 @@ target = NodePath("../Player")
|
||||
|
||||
[node name="Camera" type="Camera3D" parent="Camera_pivot" unique_id=205599850]
|
||||
|
||||
[node name="Player" parent="." unique_id=1103279396 node_paths=PackedStringArray("view") instance=ExtResource("4_ws1nr")]
|
||||
[node name="Player" parent="." unique_id=1103279396 node_paths=PackedStringArray("view", "timer") instance=ExtResource("4_ws1nr")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.27383035, 0.003461957, -3.6754417)
|
||||
view = NodePath("../Camera_pivot")
|
||||
timer = NodePath("Timer")
|
||||
|
||||
[node name="Timer" type="Timer" parent="Player" unique_id=787181895]
|
||||
wait_time = 0.3
|
||||
one_shot = true
|
||||
|
||||
[node name="block-grass2" parent="." unique_id=1963880729 instance=ExtResource("4_v3d7h")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.8063726, 1.880791e-37, -3.5159442)
|
||||
|
||||
[node name="block-grass3" parent="." unique_id=574078967 instance=ExtResource("4_v3d7h")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.2028437, 1.880791e-37, -7.068507)
|
||||
|
||||
[node name="block-grass4" parent="." unique_id=1879882826 instance=ExtResource("4_v3d7h")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.0017414, 1.1920929e-07, -6.181142)
|
||||
|
||||
[node name="block-grass5" parent="." unique_id=787080299 instance=ExtResource("4_v3d7h")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.811377, 1.1096659, -3.6591759)
|
||||
|
||||
[node name="block-grass6" parent="." unique_id=1341235001 instance=ExtResource("4_v3d7h")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6.9334083, 2.3500347, -3.9486947)
|
||||
|
||||
[node name="block-grass7" parent="." unique_id=1614115200 instance=ExtResource("4_v3d7h")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -8.555201, 3.5995975, -3.9474897)
|
||||
|
||||
[connection signal="timeout" from="Player/Timer" to="Player" method="_on_timer_timeout"]
|
||||
|
||||
Reference in New Issue
Block a user