Inconsistent jumping with Character Controller

Rodd 2 years ago updated 1 year ago 2

Hi everyone, new Bolt user here.

I'll preface my issue by saying here that I have no programming background whatsoever, but I was interested in tinkering around Bolt to see if I could make some functional games, even if they're pretty simple. So please bear with me here if this is too obvious an answer. I do know some algorithm stuff and the basics of C#.

Anyway, I decided to try and make a basic 3D controller for myself, just learning and experimenting. Currently it's a cylinder, and it can move around and jump (I'm not using physics. I'm doing everything with a Character Controller component and Bolt). And as far as I know, my code is nothing too complex, and yet, the jumping on the character doesn't really make sense. It's far too inconsistent. Sometimes the character jumps the correct height, sometimes a little more (or a lot more!). And it's apparently completely random.

Can anyone shed some light in what's going on? I'm attaching my Macro and a gif of what's going on. But basically my jump works by:

-If the character is grounded, then he has a Y value of "-1" on his moveDirection variable (that's the vector3 that gets multiplied by delta time and fed into the Character Controller Move node at the end of Update);

-If the character is NOT grounded, then the Y value of moveDirection gets the Y value of the Physics.Gravity node added to it every frame.

-Jumping is a simply "if the character is grounded and presses Space" then set the Y value of moveDirection to be the value of jumpForce (an object variable that you can set to increase or decrease the height of the jump).

The rest of the code is pretty much just dealing with GetAxis and other stuff like that for movement (which works fine). But why is the jumping so inconsistent?

My CC.asset

Bolt Version:
Unity Version:
Unity 2018.3.14f1 (64-bit)
Windows 8.1 64bits
Scripting Backend:
.NET Version (API Compatibility Level):

It's hard to tell without seeing the graph. Are you sure you're not using rigidbody which is physics based?

Also, does this issue persists in a build or is it an editor only thing?

EDIT: I also highly recommend upgrading your Bolt and Unity versions. There have been many fixes and optimizations since 1.4.1.

Hi again.

So, a 2 weeks later, my post hasn't really appeared for whatever reason, as it's apparently "on moderation".

But I wanted to say that I dug online a little bit, and I saw people talking about inconsistencies in Update vs FixedUpdate.

Pretty much everywhere I looked said that FixedUpdate should be used to handle Physics and RigidBodies. Since I was using a Character Controller and no physics whatsoever, there would be no need for that, right?

That being said, I started trying a bunch of stuff with it, and I found out that if I use Update to handle Input and Action (moving the character and jumping, in this case) and FixedUpdate to handle the gravity, then the inconsistencies with the jump vanish!

Gravity is being applied with a "isGrounded" check, if the character is not grounded, then add gravity every frame, and if the character is grounded, just set Y to -1. It's all on the first picture of my last post, but I don't know if it'll show up here. Either way, I wasn't really using physics to move it at all (since it doesn't even have a RigidBody component), I was just using the physics.gravity.y value (which, afaik, is just a constant value set in Project Settings) to pass onto a Vector3. I tried removing this node as well, and just setting a literal float of -10 to add every frame onto the character, but it didn't work. FixedUpdate is the only thing that resolved my problem, but I have no idea why.

Either way, thanks TowerCrow for the help here.