Welcome to the forums @pedro_luis12345!
To answer your questions:
what is the reason of moving a kinematic2d (or any kind of body) with move_and_slide/collide methods, can't we just use the position property for this?
You can just modify position
directly if you want, but the physics world will not be taken into account if you do. If you are modifying the position
property directly, you will be able to move into solid objects, like walls and the floor. Using move_and_slide
or move_and_collide
will attempt to move the KinematicBody2d node by the given velocity/offset, but if the object would move into a solid object, like a StaticBody2D, RigidBody2D, or another KinematicBody2D, it will use Godot's physics engine to resolve the collision. How the physics engine resolves the issue depends on the node, like a KinematicBody2D node colliding with a RigidBody2D node will cause the RigidBody2D node to be pushed, for example.
Anyway, the gist is that you want to use move_and_slide
and move_and_collide
when you want to take physics into account. If you do not want to take physics into account, then modifying position
directly will work as expected.
if i want to get the angle between two vectors (vector2.angle_to) should i use the position vector instead of the movement one, right?, because once i stop pressing a key, the vector becomes 0,0
There are several ways to do it. One way, is to get the position of one vector relative to the other, and then use atan2
to get the angle. For example:
# We'll assume pos_1 and pos_2 are the two
# vectors, and we'll assume they are both
# global positions.
# first, we need to get the direction that pos_1
# points to pos_2
var pos_1_dir = pos_1.direction_to(pos_2)
# then, we can use Atan2 to get the angle from the
# direction
var pos_1_atan_angle = atan2(pos_1_dir.y, pos_1_dir.x)
print ("Angle from Pos_1 to Pos_2: ", rad2deg(pos_1_atan_angle))
# You can also use the angle function to skip manually
# using atan2 (the angle function uses it under the hood)
var pos_1_angle = pos_1_dir.angle()
print ("Pos_1_angle: ", rad2deg(pos_1_angle ))
idk if my question may sound kinda "stupid", but i'm just confused about why we move a body with a different method instead of just using the position property
No worries! You cannot know what you don't know! :smile: