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
|
||||
|
||||
var sees_player : bool
|
||||
|
||||
# Only used for Debugging purposes right now
|
||||
var player_positions : Array
|
||||
|
||||
func _ready():
|
||||
|
@ -20,9 +22,7 @@ func _ready():
|
|||
ray.target_position = Vector2(max_view_distance, 0)
|
||||
pass
|
||||
|
||||
func view():
|
||||
# Swipe the Raycast instead of using a lot to get better performance
|
||||
|
||||
func swipe_view():
|
||||
# Set Raycast to starting position
|
||||
ray.rotation_degrees = -angle_cone_of_vision / 2
|
||||
|
||||
|
@ -56,10 +56,9 @@ func view():
|
|||
ray.rotation_degrees += angle_cone_of_vision / sweeping_steps
|
||||
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
|
||||
var hit_angles = view()
|
||||
var hit_angles = swipe_view()
|
||||
|
||||
# If The Player cant be seen, return and do nothing
|
||||
if hit_angles.size() <= 0:
|
||||
|
@ -75,16 +74,10 @@ func rotate_to_player(delta : float):
|
|||
|
||||
# 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)
|
||||
|
||||
pass
|
||||
|
||||
func _physics_process(delta):
|
||||
rotate_to_player(delta)
|
||||
pass
|
||||
|
||||
func _process(delta):
|
||||
if debug_vision:
|
||||
queue_redraw()
|
||||
look_at_player(delta)
|
||||
pass
|
||||
|
||||
func _draw():
|
||||
|
@ -96,7 +89,7 @@ func _draw():
|
|||
for step in sweeping_steps + 1:
|
||||
self.draw_line(Vector2(), Vector2(max_view_distance,0).rotated(deg_to_rad(angle)), Color.DARK_RED, 0.5, false)
|
||||
angle += angle_cone_of_vision / sweeping_steps
|
||||
|
||||
|
||||
# Draw Ray Arc
|
||||
self.draw_arc(Vector2(), max_view_distance, deg_to_rad(-angle_cone_of_vision / 2), deg_to_rad(angle_cone_of_vision / 2), sweeping_steps + 1, Color.RED, 0.5, false)
|
||||
|
||||
|
@ -104,5 +97,6 @@ func _draw():
|
|||
if sees_player:
|
||||
for pos in player_positions:
|
||||
self.draw_circle(pos, 4, Color.ORANGE_RED)
|
||||
queue_redraw()
|
||||
pass
|
||||
|
||||
|
|
|
@ -2,17 +2,15 @@ extends CharacterBody2D
|
|||
|
||||
@export var speed = 50
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
func get_input():
|
||||
func get_move_vector():
|
||||
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down").normalized()
|
||||
return input_direction
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta):
|
||||
self.velocity = get_input() * speed
|
||||
self.move_and_slide()
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
# Set Velcoity to Move Vector times speed
|
||||
self.velocity = get_move_vector() * speed
|
||||
# Do the Physics-Calculations of the Player
|
||||
self.move_and_slide()
|
||||
pass
|
||||
|
||||
|
|
Reference in a new issue