How did I use VECTOR 2 as a POSITION?

Specifically, I want to use the collision point of a RayCast2D as a position to move an Object in that same place:

if RayCast2D.is_colliding():
HitPoint.global_position = RayCast2D.get_collision_point()

The problem is that “get_collision_point()” returns a Vector2, not a position

Every single time I try Vector 2 as a value to change a position it gives me an error:

Invalid set index ‘global_position’ (on base: ‘Vector2’) with value of type ‘Vector2’.

Both are literally the same type value

Did someone have a way to use a Vector 2 to change a position?

From your description and error message, it looks like HitPoint is a Vector2 and not a node.
Have your tried HitPoint = RayCast2D.get_collision_point()?
More context would help to pinpoint the problem.

Sorry, I didin’t clarify, yep, HitPoint is a variable, intended to be used to then change the node position (“Node2D.position = HitPoint”), so yea is not a node, I’ve tried what you recommend, but got the same issue, returns a Vector2, can’t use it for position

It would help, if you could show the exact error message and your code, that the error points to.
Also a Vector2 represents a position (a 2D-position).

I got a solution:
Setting a Vector2 directly into a position gives you an error, but setting x and y separately works fine by some reason, something like this:

HitPoint = RayCast2D.get_collision_point()

Node2D.position.x = HitPoint.x

Node2D.position.y = HitPoint.y

Is literally the same result that “Node2D.position = HitPoint” but Godot doesn’t take it wich is really weird, in Unity you can use Vector2 and positions as equals, hope that we can make the same in Godot in a future

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.