dev-base #36
3 changed files with 17 additions and 10 deletions
|
@ -20,7 +20,6 @@ layer_0/tile_data = PackedInt32Array(1114138, 262144, 1, 1048602, 0, 1, 983066,
|
||||||
position = Vector2(203, 60)
|
position = Vector2(203, 60)
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
script = ExtResource("2_pk6k4")
|
script = ExtResource("2_pk6k4")
|
||||||
speed = 100
|
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="Player"]
|
[node name="Sprite2D" type="Sprite2D" parent="Player"]
|
||||||
texture = ExtResource("2_0flm2")
|
texture = ExtResource("2_0flm2")
|
||||||
|
|
|
@ -90,9 +90,9 @@ func look_at_player(delta : float) -> float:
|
||||||
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)
|
||||||
return average_angle
|
return average_angle
|
||||||
|
|
||||||
func follow_player(angle : float):
|
func follow_player(angle : float, delta : float):
|
||||||
if(target_distance > follow_keep_distance):
|
if(target_distance > follow_keep_distance):
|
||||||
self.apply_central_force(Vector2.RIGHT.rotated(self.rotation).rotated(deg_to_rad(angle)) * speed)
|
self.apply_central_force(Vector2.RIGHT.rotated(self.rotation).rotated(deg_to_rad(angle)) * speed * delta * 60)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ func _physics_process(delta: float):
|
||||||
var angle := look_at_player(delta)
|
var angle := look_at_player(delta)
|
||||||
match state:
|
match state:
|
||||||
STATES.TARGETING:
|
STATES.TARGETING:
|
||||||
follow_player(angle)
|
follow_player(angle, delta)
|
||||||
STATES.IDLE:
|
STATES.IDLE:
|
||||||
# Do Idle Stuff
|
# Do Idle Stuff
|
||||||
print("Dam, Nice a pause, time for a Coffee")
|
print("Dam, Nice a pause, time for a Coffee")
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
@export var speed = 50
|
@export var speed = 100
|
||||||
|
@export_range(0, 1) var damping_factor := 0.6
|
||||||
|
|
||||||
func get_move_vector():
|
func get_move_vector():
|
||||||
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
|
||||||
|
|
||||||
|
func move_player(delta : float):
|
||||||
func _physics_process(delta):
|
if get_move_vector() == Vector2.ZERO:
|
||||||
# Set Velcoity to Move Vector times speed
|
# Damp Players Velocity if no Input
|
||||||
self.velocity = get_move_vector() * speed
|
self.velocity = self.velocity * (1 - min(1, damping_factor * 60 * delta))
|
||||||
# Do the Physics-Calculations of the Player
|
else:
|
||||||
|
# Set Players Velocity to the Input Direction in the Players Speed
|
||||||
|
self.velocity = get_move_vector() * speed * delta * 60
|
||||||
|
|
||||||
|
# Update The Players Physics Calculations
|
||||||
self.move_and_slide()
|
self.move_and_slide()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func _physics_process(delta : float):
|
||||||
|
move_player(delta)
|
||||||
|
pass
|
||||||
|
|
Reference in a new issue