obsidian/MyObsidianVault/Godot/2D/Tutorial M4 - to space and beyond/01. turning image towards direction (setting rotation).md
2024-12-22 12:24:50 +01:00

16 lines
No EOL
662 B
Markdown

Sprite2D node
F => focus view on object
To get type information in code auto-completion, go to _Editor -> Editor Settings_, and in the _Text Editor -> Completion_ section, turn on the checkbox named _Add Type Hints_. You can also search for "type hints" in the search bar at the top of the window to find it quickly.
`Vector2` values have a function named `angle()` that calculates and returns the vector's angle in radians. If we assign that to the ship's rotation, it will turn to face its move direction.
```gdscript
var velocity = Vector2(480, -480)
func _process(delta: float) -> void:
position += velocity * delta
rotation = velocity.angle()
````