r
rifqilubis

About velocity

var velocity := Vector2(500, 0)

func _process(delta: float) -> void:

    position += velocity * delta

    rotation = velocity.angle()


Why you need  rotation = velocity.angle()

instead of   rotation = velocity


aren't they the same? or godot can't understand what you typed, because you didnt input angle function?


im kinda confused when you need angle function.

  • r
    rifqilubis replied

    does angle function, used to read the Vector2() function?

  • Nathan Lovato replied
    Solution

    A rotation is a single decimal value. Here the rotation is measured in radians, so a value of 2 * PI represents a full turn.

    We use a 2D vector for the velocity. It has two decimal values: an X and a Y value. This is incompatible with the angle, which requires a single decimal value. That's why we need to call the function Vector2.angle() (in the code  rotation = velocity.angle()) : it takes care of calculating the angle of our velocity vector.

    2 loves