Update do projeto ate a aula 10
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
|
||||
const SPEED := 100.0
|
||||
const CHASE_RANGE := 8.0
|
||||
|
||||
@export var target : CharacterBody3D
|
||||
@onready var nav_agent: NavigationAgent3D = $nav_agent
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
velocity = Vector3.ZERO
|
||||
|
||||
if global_position.distance_to(target.global_position) < CHASE_RANGE:
|
||||
nav_agent.target_position = target.global_transform.origin
|
||||
var next_nav_point = nav_agent.get_next_path_position()
|
||||
velocity = (next_nav_point - global_transform.origin).normalized() * SPEED * delta
|
||||
look_at(Vector3(target.global_position.x, global_position.y, target.global_position.z), Vector3.UP)
|
||||
|
||||
move_and_slide()
|
||||
@@ -0,0 +1 @@
|
||||
uid://bkr4jcakebo3n
|
||||
@@ -7,11 +7,8 @@ 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)
|
||||
@@ -19,13 +16,6 @@ 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
|
||||
@@ -65,14 +55,8 @@ func apply_gravity(delta):
|
||||
gravity += 25 * delta
|
||||
|
||||
func jump():
|
||||
if Input.is_action_just_pressed("move_jump") and can_jump:
|
||||
if Input.is_action_just_pressed("move_jump") and is_on_floor():
|
||||
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
|
||||
|
||||
+2627
-31
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user