perf: reduce frequency of police navagent updates
This commit is contained in:
parent
5b417b540b
commit
370eb54163
2 changed files with 13 additions and 1 deletions
|
|
@ -1,13 +1,25 @@
|
|||
class_name PoliceCar
|
||||
extends CharacterBody3D
|
||||
|
||||
const FRAME_IDXS := 10
|
||||
|
||||
@export var dot_curve: Curve
|
||||
|
||||
var health := 10.
|
||||
var frame_idx := 0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
func _ready() -> void:
|
||||
frame_idx = randi() % FRAME_IDXS
|
||||
|
||||
func _update_nav_agent() -> void:
|
||||
%NavAgent.target_position = Player.instance.global_position
|
||||
|
||||
var frame_count := 0
|
||||
func _process(delta: float) -> void:
|
||||
frame_count = (frame_count + 1) % FRAME_IDXS
|
||||
if frame_count == frame_idx:
|
||||
_update_nav_agent()
|
||||
|
||||
var dir := global_position.direction_to(%NavAgent.get_next_path_position())
|
||||
dir.y = 0
|
||||
var dot_power := dot_curve.sample(dir.dot(velocity.normalized()))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue