mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 15:00:09 +01:00
This leads to code that is easier to understand and runs faster thanks to GDScript's typed instructions. The untyped declaration warning is now enabled on all projects where type hints were added. All projects currently run without any untyped declration warnings. Dodge the Creeps and Squash the Creeps demos intentionally don't use type hints to match the documentation, where type hints haven't been adopted yet (given its beginner focus).
17 lines
483 B
GDScript
17 lines
483 B
GDScript
extends CharacterBody2D
|
|
|
|
const MOTION_SPEED = 30
|
|
const FRICTION_FACTOR = 0.89
|
|
const TAN30DEG = tan(deg_to_rad(30))
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
var motion := Vector2()
|
|
motion.x = Input.get_axis(&"move_left", &"move_right")
|
|
motion.y = Input.get_axis(&"move_up", &"move_down")
|
|
# Make diagonal movement fit for hexagonal tiles.
|
|
motion.y *= TAN30DEG
|
|
velocity += motion.normalized() * MOTION_SPEED
|
|
# Apply friction.
|
|
velocity *= FRICTION_FACTOR
|
|
move_and_slide()
|