Cleanup Code
This commit is contained in:
parent
502d0c440d
commit
5c52c04acb
2 changed files with 16 additions and 24 deletions
|
@ -13,6 +13,8 @@ extends Node2D
|
||||||
@export var debug_vision := false
|
@export var debug_vision := false
|
||||||
|
|
||||||
var sees_player : bool
|
var sees_player : bool
|
||||||
|
|
||||||
|
# Only used for Debugging purposes right now
|
||||||
var player_positions : Array
|
var player_positions : Array
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
@ -20,9 +22,7 @@ func _ready():
|
||||||
ray.target_position = Vector2(max_view_distance, 0)
|
ray.target_position = Vector2(max_view_distance, 0)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func view():
|
func swipe_view():
|
||||||
# Swipe the Raycast instead of using a lot to get better performance
|
|
||||||
|
|
||||||
# Set Raycast to starting position
|
# Set Raycast to starting position
|
||||||
ray.rotation_degrees = -angle_cone_of_vision / 2
|
ray.rotation_degrees = -angle_cone_of_vision / 2
|
||||||
|
|
||||||
|
@ -56,10 +56,9 @@ func view():
|
||||||
ray.rotation_degrees += angle_cone_of_vision / sweeping_steps
|
ray.rotation_degrees += angle_cone_of_vision / sweeping_steps
|
||||||
return hit_angles
|
return hit_angles
|
||||||
|
|
||||||
func rotate_to_player(delta : float):
|
func look_at_player(delta : float):
|
||||||
|
|
||||||
# Get All Angles at which the Player can be seen
|
# Get All Angles at which the Player can be seen
|
||||||
var hit_angles = view()
|
var hit_angles = swipe_view()
|
||||||
|
|
||||||
# If The Player cant be seen, return and do nothing
|
# If The Player cant be seen, return and do nothing
|
||||||
if hit_angles.size() <= 0:
|
if hit_angles.size() <= 0:
|
||||||
|
@ -75,16 +74,10 @@ func rotate_to_player(delta : float):
|
||||||
|
|
||||||
# Rotate towards Player, but limit it by rotation speed
|
# Rotate towards Player, but limit it by rotation speed
|
||||||
self.rotation_degrees += clampf(average_angle, -2 * PI * delta * turn_speed, 2 * PI * delta * turn_speed)
|
self.rotation_degrees += clampf(average_angle, -2 * PI * delta * turn_speed, 2 * PI * delta * turn_speed)
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
rotate_to_player(delta)
|
look_at_player(delta)
|
||||||
pass
|
|
||||||
|
|
||||||
func _process(delta):
|
|
||||||
if debug_vision:
|
|
||||||
queue_redraw()
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _draw():
|
func _draw():
|
||||||
|
@ -104,5 +97,6 @@ func _draw():
|
||||||
if sees_player:
|
if sees_player:
|
||||||
for pos in player_positions:
|
for pos in player_positions:
|
||||||
self.draw_circle(pos, 4, Color.ORANGE_RED)
|
self.draw_circle(pos, 4, Color.ORANGE_RED)
|
||||||
|
queue_redraw()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -2,17 +2,15 @@ extends CharacterBody2D
|
||||||
|
|
||||||
@export var speed = 50
|
@export var speed = 50
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
func get_move_vector():
|
||||||
func _ready():
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
func get_input():
|
|
||||||
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down").normalized()
|
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down").normalized()
|
||||||
return input_direction
|
return input_direction
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
self.velocity = get_input() * speed
|
# Set Velcoity to Move Vector times speed
|
||||||
|
self.velocity = get_move_vector() * speed
|
||||||
|
# Do the Physics-Calculations of the Player
|
||||||
self.move_and_slide()
|
self.move_and_slide()
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
Reference in a new issue