Difference between vector3 and get_position?

In the object setting, I’ve prescribed that the z-position is 1 (greater than the background position), but if I spawn the monsters like this:

{...}
local position  = vmath.vector3(800, 200, 1)
{...}
factory.create(monster[monster_name].factory_url, position, nil, {damage = monster[monster_name].damage, speed = monster[monster_name].speed, hp = monster[monster_name].hp, height = monster[monster_name].height, experience = monster[monster_name].experience})

They will still appear behind the backgound

image
You may not be able to see the monster, but it’s beating the slime right now.

Но если я реализую код таким образом:

{...}
self.position = go.get_position()
self.position.x = 800
self.position.y = 200
{...}
factory.create(monster[monster_name].factory_url, self.position, nil, {damage = monster[monster_name].damage, speed = monster[monster_name].speed, hp = monster[monster_name].hp, height = monster[monster_name].height, experience = monster[monster_name].experience})

Then the monster becomes visible
image

Почему при спавне с использованием vector3, моб не получат указанную z-позицию ? (для справки - z-позиция фона меньше 1)

What is this value if you print it?

DEBUG:SCRIPT: vmath.vector3(0, 0, 0)

In that case, it’s even weirder considering I don’t specify z-position, except when spawning a monster in position…

I got it ! Spawning an object at z-position is not the same as giving the sprite a location at z-position. When spawning via vmath.vector(800, 200, 1) I get to spawn the object itself on a completely different layer.

PS. Did I understand my mistake correctly ?

Correct. The position you give is for the game object. Components such as sprites are then offset from this position.

3 Likes