• Projects
  • using add_central_force: how to set limit for maximum velocity

My brain is dead today. How can I set maximum velocity for add_central_force?

add_central_force(move_force* global_transform.basis.z)

I am using this to move around a small sphere and it works fine- but if you hold the forward key down then the velocity keeps increasing till you fly off the screen.

Can you use just_pressed instead of pressed? or do you want it to build for a while and then stop?

@fire7side said: Can you use just_pressed instead of pressed? or do you want it to build for a while and then stop?

I ended up just adding this check to this button keys: if linear_velocity.length()<20:

this seems to work fine.

When using a rigidbody, I use linear_velocity=direction*speed direction being a Vector3

But I've been using kinematic Body for my projects.

You have to override _integrate_forces() to set limits. This is the correct way, but you can also add damping in the inspector (sort of like friction) and if you tweak the numbers you might get something okay.

@cybereality said: You have to override _integrate_forces() to set limits. This is the correct way, but you can also add damping in the inspector (sort of like friction) and if you tweak the numbers you might get something okay.

I think his code might be all right because it limits it before it ever happens.

The body's linear velocity in units per second. Can be used sporadically, but don't set this every frame, because physics may run in another thread and runs at a different granularity. Use _integrate_forces as your process loop for precise control of the body state.

Yes, but if you are calling that every frame (60 frames per second) then it is going to add up and cause a rapid acceleration. Though you could just make the force you enter smaller, if you hold the key long enough it will increase in speed forever. Using integrate forces will allow you to cap the velocity or force or any other value which is not shown in the inspector.

@cybereality said: Yes, but if you are calling that every frame (60 frames per second) then it is going to add up and cause a rapid acceleration. Though you could just make the force you enter smaller, if you hold the key long enough it will increase in speed forever. Using integrate forces will allow you to cap the velocity or force or any other value which is not shown in the inspector.

I will research it. Currently my code works and the acceleration is stopped.

The issue now is if the character runs to the bottom of the planet he flips upside down. I assume its because I am using gravity direction incorrectly but Ill look at that morrow