Many different bullet factories

Hi all,

I have a questions about a character with many factories with different bullets.

My current idea was to have a collectionfactory for that character and create the factories if a new weapon is added. The other factories should also still be active.

I tried to do this approach and realised that if i create a new collection from the proxy i load, that the factory is in a different “world” collection and i cannot access my players position anymore.

Should i have a factory for each bullet type on the player and start them on a timer when i get an upgrade?

or what would be the best approach. I try to do something like Vampire Survivor where the weapons get added during runtime.

Thanks in advance.

I might be missing something but I struggle to see why you would load collection proxies. I would have a player game object with X number of different factories each associated with a weapon. If that weapon is active, the player script spawns objects using the relevant factory component on the player object.

In my mind a collection proxy is for big containers like “main menu” and “game” etc, and factories (or collection factories) are for things like “player” or “enemy” or “weapon”.

2 Likes

Thanks for the clarification.

I first thought i have to do this over a collectionfactory, that is why i needed the collectionc files generated by the proxy to swap the prototype in the collectionfactory.

I will do the approach with different factories. Thanks.

Getting more and more familiar with the engine it has not been a week^^.

1 Like

Good luck!

I made this, which seems to be similar to what you are making:

So I kind of know what you are dealing with.

This sounds to me like you risk overcomplicating things. I don’t do any prototype swapping in Void Scrappers.

If you have bullets with very similar behaviours (e.g. just varying in terms of speed, damage, visual, etc) I would actually just use one single factory. I would create a table of bullet properties:

local bullet_types = {
    regular = {speed = 200, flipbook = "reg", damage = 1},
    large = {speed = 100, flipbook = "lrg", damage = 3},
}

When spawning I get the data from the bullet types table and apply it as required, then store the produced bullet in another table:

local function spawn_bullet(bullet_type)

    local bullet_data = bullet_types[bullet_type]

    local object = factory.create("#bullet_factory")

    --play the appropriate flipbook based on bullet_data.flipbook

    --insert the bullet into a table to track it
    table.insert(active_bullets, {
        object = object,
        speed = bullet_data.speed,
        damage = bullet_data.damage,
    })

end

Then to process bullets:

local function process_bullets(dt)


    for i, bullet in ipairs(active_bullets) do

        --update position based on bullet.speed

        --check for collision maybe? depends how you do it!
        --if collision, then apply damage based on bullet.damage

    end

end

There is a lot more to it than this of course, but I just want to give a rough idea of how I handle something like this. Would love to hear other people’s opinions as well.

5 Likes

There’s an example here where a single factory is used for bullets and the bullet prototype gets changed:

It could be a solution to consider maybe?

3 Likes

Thank you so much! I saw your game just recently when i was researching! Looks really cool I should give it a try and I hope I can ask you in the future about certain things.

I can see this work for some but for something like “Garlic” it would not work right.

Right now i have modules Knife.lua, Garlic.lua these contain the data and information about the weapon, as well as a Weapon.lua module which holds all the weapon modules

For each weapon factory i have one script that updates all the bullets. (knife_controller) and so on.

I have a main script “Game_Controller” which is like a central controller for messages like, (start_game, level_up_start, level_up_end …) It sends msgs from there to the involved objecets/scripts.

I was not 100% sure about the use of modules, i also have one for “Game_State” and “Player_Data”. It feels like i can organize the code well like that.

Does this make sense?

1 Like

I saw this one and the “bullets” in this game will have all different behaviours. But Thank you for the suggestions.

Yeah this all sounds very reasonable!

Good luck with your project.

1 Like

Thank you and you with your next game too!

1 Like