How to make a variable that is a variable plus a int

Godot Version

4.4

Question

`so I have the players location in a global variable and I want to make an object in this case a laser spawn 469 pixels or units or whatever measurement it is infront of the player but if I try

spawn(Vector2(Global.player_position + 469,0))

it just throws an error what do I do also spawn is the function that spawns the laser

You need to do spawn(Global.player_position +Vector2(469, 0))

1 Like

thanks

1 Like

wait how do I make it only the x axis

spawn(Global.player_position.x + Vector2(469,randf_range(93,-214)))

throws an error

the spawn position takes in a Vector2 right? then spawn(Global.player_position + Vector2(469,randf_range(93,-214))) You can think of it like this

spawn(
    Global.player_position,
    Vector2(
        469,
        randf_range(93, -214)
    )
)

If you want the spawn function to take in a float instead of a Vector2 you need to modify the spawn function as well.

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