Hello!
I’ve set up a character controller that allows to shoot in the direction of mouse cursor relative to player.
However, bullets just disappear after travelling twice the distance from player to mouse position. They are still in the scene but just don’t render anymore.
What could be wrong? Could the problem be in Z-coordinates? (Player has z=1, and mouse cursor has z=0)
Here’s the code I am using for creating bullets:
function combat(self)
local player_pos = go.get_position()
self.look_dir = vmath.normalize(mouse_pos - player_pos)
local shoot_angle = math.atan2(self.look_dir.y, self.look_dir.x)
local bullet_rot = vmath.quat_rotation_z(shoot_angle)
local props = { dir = self.look_dir }
factory.create("#projectile_factory", nil, bullet_rot, props)
print("mouse is at: " .. mouse_pos, "player is at" .. player_pos)
self.shooting = false
end
I can attach full script/project, if there is not enough context.