How to set a random position of a game object?

I just really want to know how to set a random position of a game object.

I have been using this code

function update(self, dt)
x, y = math.random(1,10), math.random(1,10)
print(x)
print(y)
pos = vmath.vector(x, y)
go.set_position(pos)
end

and it just ends up in a error.

Hi!

I think I have spotted the error, you need to change vmath.vector(x, y) into vmath.vector3(x, y, 0). :slight_smile:

  • vmath.vector can construct a vector with custom length, usable when creating custom easing curves.
  • vmath.vector3 creates a 3D vector which is what go.set_position expects, as you can see in the documentation.
3 Likes

It was so far ago I asked this so now I don’t know for what project I asked this for. :rofl:

1 Like