I am trying to execute the War battles tutorial. So far no success of spawning the rockets at the right position…
Somehow they appear moved from the actual player position… - I have added screenshot
Also here is my code calling the factory.create from player.script:
local angle = math.atan2(self.dir.y, self.dir.x) -- [1]
local rot = vmath.quat_rotation_z(angle) -- [2]
local props = { dir = self.dir } -- [3]
factory.create("#rocketfactory", nil, rot, props) -- [1]
And rocket.script:
go.property("dir", vmath.vector3()) -- [1]
function update(self, dt)
local pos = go.get_position() -- [3]
pos = pos + self.dir * self.speed * dt -- [4]
go.set_position(pos) -- [5]
end
If you take a look at the gameobjects for both the player and the rockets, what position does the sprite components have? Do they have any offset? I would suspect that they should be centered at the origin of each gameobject, ie have position (0, 0, 0).
Just like the tutorial is stating for the player :
Change the Z Position property of the game object named “player” to 1.0. Since the “map” game object is at the default Z position 0 the “player” game object must be at a higher value (between -1.0 and 1.0) for it to be on top of the level.
Make sure that the Z Position of the Sprite is 0 so it will be rendered at the same depth as the game object “player”. Setting the Z to a different value will offset the sprite depth from 1.0, which is the Z position of the game object.
The rockets do not have sprite added to main.collection. For them there is only factory under the player object.
Should I check what I can do with the factory component?
The factory should point to a rocket gameobject, that gameobject should have a sprite, the visual representation of the rocket. This is the sprite and position I’m asking about.
If this sprite is centered in origo for the gameobject, I would suggest you verify the position of the factory component itself. Since you don’t supply a position to the function call;
factory.create("#rocketfactory", nil, rot, props)
Then the position of the factory will be used instead for the position of the spawned gameobjects.
In short, verify;
the factory component is centered in the player gameobject
the sprite component in the rocket gameobject should be centered
the sprite component in the player gameobject should be centered
I just wanted to position the player’s sprite at the begging to be somewhat in the center of the screen and not at lower left corner (0,0)
I will have to figure out how to do it later on. (I am open for suggestions )
Thank you guys again for the quick and accurate response