https://www.youtube.com/watch?v=g7yUeT0GA04
I’m having a problem with my character’s projectile. The projectile appears to be launched outside the sprite, very far away. What could be the problem?
I’ve attached a reference video.
https://www.youtube.com/watch?v=g7yUeT0GA04
I’m having a problem with my character’s projectile. The projectile appears to be launched outside the sprite, very far away. What could be the problem?
I’ve attached a reference video.
Could you share more about the implementation? How do you set/calculate the position where bullet is spawned?
local function fire(self)
self.velocity.x = self.velocity.x + RECOIL * -self.direction
local pos = go.get_position()
-- offset the bullet so that it is fired "outside" of the player sprite
pos.x = pos.x + 8 * self.direction
local id = factory.create("#bulletfactory", pos)
-- flip the bullet sprite
sprite.set_hflip(msg.url(nil, id, "sprite"), self.direction == -1)
-- move the bullet 300 pixels and then delete it
local distance = 300
local to = pos.x + distance * self.direction
local duration = distance / 250
go.animate(id, "position.x", go.PLAYBACK_ONCE_FORWARD, to, go.EASING_LINEAR, duration, 0, function()
go.delete(id)
end)
end
Your code looks fine to me.
Could something else be offsetting the sprite? Perhaps it’s not centred in the game object or the pivot point is set wrong in the atlas?
I bet the sprite is offset from the spawned game object or something similar