27 lines
1.1 KiB
Plaintext
27 lines
1.1 KiB
Plaintext
(var &mut :Spatial pivot null)
|
|
(var &mut :Vector3 _velocity Vector3.ZERO)
|
|
|
|
(method &public &override :Void _Ready []
|
|
(set pivot (cast (getNode "Pivot") Spatial)))
|
|
|
|
(method &public &override :Void _PhysicsProcess [:Single delta]
|
|
(let [&mut direction Vector3.ZERO]
|
|
(when (Input.isActionPressed "move_right")
|
|
(+= direction.x 1))
|
|
(when (Input.isActionPressed "move_left")
|
|
(-= direction.x 1))
|
|
(when (Input.isActionPressed "move_backward")
|
|
(+= direction.z 1))
|
|
(when (Input.isActionPressed "move_forward")
|
|
(-= direction.z 1))
|
|
|
|
(when !(= direction Vector3.ZERO)
|
|
(set direction (direction.normalized))
|
|
// TODO for some reason, the Vector3 addition operator is only found when used in a raw haxe expr:
|
|
(pivot.lookAt #{translation + direction;}# Vector3.UP))
|
|
|
|
(set _velocity.x (* direction.x speed))
|
|
(set _velocity.z (* direction.z speed))
|
|
(-= _velocity.y (* fallAcceleration delta))
|
|
(set _velocity (moveAndSlide _velocity Vector3.UP))
|
|
)) |