what would i put in the bracket to fetch the sprite location of a specific object? I’m trying to get a system set up to spawn sprites on an object, sort of like an artefact pedestal in a rogue-like.
function init(self)
math.randomseed(100000000000000 * (socket.gettime() % 1))
for i=1,20 do
math.random()
end
end
function update(self, dt)
local seed = math.random(1,4)
if seed == 1 then
local pos = vmath.vector3(objectposition) <--
factory.create("#damagebuff", pos)
end
end
You don’t get the position of a sprite. You can only get the position of game objects, which you do like this:
go.get_position("pedestal")
So for you that would be:
local pos = go.get_position("pedestal")
factory.create("#damagebuff", pos)
Or shorthand:
factory.create("#damagebuff", go.get_position("pedestal"))
If your question is specifically “how do I get the position of a sprite component in a game object?”, then the answer is that you still can’t. If that is something you want to do, then you would have to place the sprite in a dedicated game object, and parent that game object to the original one. Then you can get the position of the “sprite”.
4 Likes
right makes sense don’t know how I didn’t figure that out
no wait actually can you not use the sprite location? do you have to use the object location? i would of thought that getting the sprite location would be more useful since the sprite and object location is usually different.
Nope, it’s like I said in my previous post. You don’t get the position of a sprite in a gameobject, the engine is just not designed that way.
ok so it was acting weird because I accidentally put the spawner in the world object…