Spin With Rotation
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 11 of 27.
A node turns around its own position. rotation is how far it has turned, in radians. A whole turn is 2 * PI radians, about 6.28. rotation_degrees is the same angle in degrees, where a whole turn is 360. Change one and the other follows.
rotation_degrees = 90 # a quarter turn
rotation = PI / 2 # the same quarter turnA growing angle turns a node clockwise. To spin, add to the angle on every frame, times delta:
func _process(delta):
rotation_degrees += 90 * deltaThat spins a quarter turn each second. -= spins the other way.
Challenge
EasyMake the robot spin clockwise, half a turn every second, in the place where it stands.
Try it yourself
extends Node2D
func _process(delta):
pass
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Nodes and Scenes
1Your First Godot Game
What Is Godot?Ready Runs OncePrint in GodotThe Scene TreeSet a PositionMove a Node Once2Every Frame
Process Runs Every FrameDeltaPixels per SecondMove DiagonallySpin With RotationGrow With ScalePractice on your own: Godot playground