Adjusting weight/sizes in Unity

Hello, I just started learning Unity, and I’m wanting to make an inflation based game (see my idea thread here: Idea: Inflation/object inflation metroidvania/puzzle - #3 by HappyFlygon ), but I have run into an issue… I don’t know how to adjust weight/individual rig sizes in Unity. I know the rig sizes would probably need to be done in Blender and then exported to Unity, but as for the weight, I have no clue. This would need to happen for the mechanic to actually work properly. (the player character/objects would get lighter/heavier depending on the type and amount of inflation) How would I go about doing this in unity? Thank you for the help in advance!

1 Like

If they have a rigidbody component (it gives them physics), you can adjust the mass there. Otherwise you’d have to just decrease jump height and increase their falling acceleration based on weight, in code etc.

1 Like

Ya, @BloatedGoyle is right and it holds true in really all other engines as well. You can adjust the mass of a rigid body and let the engines built in physics handles some of the stuff for you but this does not work well for all games in which case you have to kind of handle the calculations yourself which can be done quite a few ways.

In past games I have done I used weight to calculate a modifier that was applied to gravity and movement speed and that tended to work well. Both ways will require some trial and error to make it feel right though.

Falling acceleration is actually constant for everything regardless of weight (except for things like feathers and balloons that have very high wind resistance compared to their mass) so I would recommend not changing this at all unless you’re going for air inflation.

I’m actually going for four types of inflation:
Helium (obvious) causes floating
O2 (decreases density)
Water (increases weight)
Fat (increases weight a LOT, can only be applied to characters, and only goes away upon next level)

How would I code these options in? I’m still very new and learning code, myself, and I don’t know where to look for the right modifiers and code.

(these options being what the three of you have listed so far, not the inflation options. I’ll start with just O2 for simplicity)

I had a similar issue with a platformer before. I had muscle, fat and hyper. I couldn’t get them to work differently enough so reworked the game entirely.

I would recommend try putting a rigidbody on your player and move them horizontally with by addint to the position (transform.position += Vector3.left) but the jump to be a force (rigidbody.addForce). For the force I recommend Impulse for the mode. Then make the jump force amount and speed a variable. The different upgrades alter these. Maybe even have 2 different speed, for on ground and in air.

Since fat floats, water would arguably be the ‘heaviest’, albeit that fat is a lot less naturally reversible when it comes to ‘inflation’.

Interesting, that could add in another aspect- Fat can float and is still heavy while water sinks.

Do you have any links to coding tutorials that would help me accomplish this? I’m still really new to doing coding.

EDIT: I’m specifically starting with a platform rather than the player, as it’s easier to modify that code and eventually the goal is to have one character be able to do that anyway.

So I have a new issue here, everyone.

I’m currently trying to set it up so the cubes can only be inflated if you’re currently touching them, using a boolean “InRange”.

The idea is to use a trigger of the box (box is parent of trigger) to set “InRange” to true when the player enters it, this part is currently functional.

InRange is then used in the if statement to inflated the cube:
“if (_PlayerMoveBasic.InRange == true && Input.KeyDown (keycode = R))
{
[insert inflation code here]
}”

The issue is, while I can easily set “InRange” to true, I currently cannot set it back to False except for by a half-second timer. This sounds ok, until you realize that it only runs the code when you touch the trigger, meaning if you take too long, you have to back off, and then ram back in.

Anyone know how to set it up to automatically set “InRange” back to false upon leaving the trigger?

So unity has both OntriggerEnter and OnTriggerExit so you can have the enter inflate, then have the exit deflate after the timer.

Unity has a lot of those auto triggered functions like update, fixedupdate etc. When you are working with something its good to google for its doc to find them.

I once scrapped a game as I found out unity has a OnMouseClick after making my own worse version.

Ohhhh, thank you so much! I shoulda thought of just changing the end bit, lmao.

'nother new problem, though I don’t know if I’m just missing the way to google it:
I want to set up my object inflation code (getting that down before I even THINK about touching the player) so that it only allows me to inflate an object when I am directly touching THAT OBJECT without having to use any new code. For instance, let’s say I have five “heavy” objects and two “light” objects, and the relations are as follows:

Light object must be heavy enough not to move at all when “water” player jumps on it, but in order to get up on it, three “heavy” objects must be inflated to different levels, and on top, heavy objects must make another staircase so the inflator character can pull a lever, revealing a weight switch for the “water” character. If the heavy objects must all be different sizes, and I don’t wanna give it away by SETTING them to different sizes at the start, I need to be able to check whether the “heavy object” instance the player touching is “Heavy-1” or “Heavy-2”, so I can ONLY manipulate that object. Maybe something to do with empty objects??? I dunno.