16 lines
1.1 KiB
Plaintext
16 lines
1.1 KiB
Plaintext
|
Ziua 1:
|
|||
|
Realizarea miscarii nodului: // circular
|
|||
|
|
|||
|
var speed = 400 # pixel per second
|
|||
|
var angular_speed = PI # radian per second
|
|||
|
|
|||
|
func _process(delta):
|
|||
|
rotation += angular_speed * delta
|
|||
|
var velocity = Vector2.UP.rotated(rotation) * speed
|
|||
|
position += velocity * delta
|
|||
|
As we already saw, the var keyword defines a new variable. If you put it at the top of the script, it defines a property of the class. Inside a function, it defines a local variable: it only exists within the function’s scope.
|
|||
|
|
|||
|
We define a local variable named velocity, a 2D vector representing both a direction and a speed. To make the node move forward, we start from the Vector2 class’s constant Vector2.UP, a vector pointing up, and rotate it by calling the Vector2 method rotated(). This expression, Vector2.UP.rotated(rotation), is a vector pointing forward relative to our icon. Multiplied by our speed property, it gives us a velocity we can use to move the node forward.
|
|||
|
|
|||
|
We add velocity * delta to the node’s position to move it. The position itself is of type Vector2, a built-in type in Godot representing a 2D vector.
|