partially for #3 Co-authored-by: Travis Gatlin <travisgatlin53@yahoo.com> Reviewed-on: #9 Reviewed-by: Travis Gatlin <travisgatlin53@yahoo.com> Co-authored-by: Yehoshua Sandler <accounts@tzed.io> Co-committed-by: Yehoshua Sandler <accounts@tzed.io>
28 lines
792 B
GDScript
28 lines
792 B
GDScript
extends CharacterBody2D
|
|
@onready var global = $"/root/Player"
|
|
|
|
const SPEED = 350.0
|
|
var charAngle = 0.0
|
|
func _physics_process(delta: float) -> void:
|
|
global.emit_signal("playerPosition",self.global_position)
|
|
movement()
|
|
|
|
func animation():
|
|
pass
|
|
|
|
func movement():
|
|
var vertical = Input.get_axis("up","down")
|
|
var horizontal = Input.get_axis("left","right")
|
|
var rotVector = Vector2(vertical*-1,horizontal)
|
|
if rotVector != Vector2(0,0):
|
|
self.set_rotation(rotVector.angle())
|
|
#limiting diagonal speed
|
|
if is_equal_approx(abs(vertical),1.0) and is_equal_approx(abs(horizontal),1.0):
|
|
velocity.y = SPEED*vertical/2
|
|
velocity.x = SPEED*horizontal/2
|
|
else:
|
|
velocity.y = SPEED * vertical
|
|
velocity.x = SPEED * horizontal
|
|
move_and_slide()
|
|
$"../Camera2D/Label".text = (str(charAngle*180/PI))
|