Support Me on Patreon

Friday, January 24, 2020

What a suck up

This entire first month was a bit rough so I haven't done much on my projects. I'm attempting to add new habits (good ones) like drawing. Gardening is something else I enjoy and I'm getting prepared for spring, when I can.

For this blog post I'll be going over a few things from Little one, such as the vacuum, crafts, and material drops. Should be a lot of fun, or at least interesting for other developers.

Vacucel:

The vacucel is the item that vacuums and collects items. Objects that can be sucked up are in a group called "Vacup" and they're all rigid body objects (nodes). In the player's script I use apply_central_impulse(power)  to pull or push the objects. Power need to be a Vector3(), so here is how I calculate it:
var power = (grabber.get_global_transform().origin - scIns.get_global_transform().origin)*-200
Grabber is the node (area) that collects the objects. There is a spatial node that I "emit" objects from. The scIns variable is the object being "emitted". This "shoots" the object after it has been added to the scene.

To attract objects, I have another area on the vacucell that adds objects that enter it to an array (list). When the mouse button is clicked, I go through the list calculating and applying the power. I replace the scIns variable with the objects I'm looping through and change the -200 to a positive number. Care has to be taken on how much power is used, lest the objects go flying around.

Crafting:
I'll start with a craft recipe:


partCraft["SignalRadio"] = {}
partCraft["SignalRadio"]["Iron"] = 2
partCraft["SignalRadio"]["Plastic"] = 5
partCraft["SignalRadio"]["Silicon"] = 1
partCraft["SignalRadio"]["Carbon"] = 1


There is a dictionary of the materials that uses the material names as the keys with the amount being an integer. I just loop through the partCraft["SignalRadio"].keys() and check if the same key in the materials has enough. When all the material needs are met, the item can be crafted with a single click. Then the materials are subtracted and the menu is refreshed.

In my next projects, crafting will have more limits on materials, this one would be fine though.

Material Drops:

These are spread throughout  the map, three for each material. A few should drop items each day. Items dropped are children of the material droppers. These child objects are counted and that number is saved. On load the material dropper will drop the saved amount of items.







No comments:

Post a Comment