Spin With Rotation
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 11 of 28.
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 where it stands.
- In
_process(), add torotation_degreesso it turns clockwise. - Make it half a turn,
180degrees, every second, withdelta.
Press Play: the robot spins on the spot, a whole turn every two seconds. Then Check.
Try it yourself
extends Node2D
func _process(delta):
pass
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