- Home /
How can I add smooth movement to a RigidBody?
I've been trying to work on a stealth game where precise, smooth movement is key. For this reason, at first, I decided to use a Character Controller on my FPS Character, however, another key element of my game is a grapple gun, this involves Springjoints, which do not seem to work with Character Controllers.
Here is a quick overview of the problem:
Character Controller:
- Pro: Movement is precise and smooth, the character only moves while the key is pressed.
- Con: Physics and Springjoints do not seem to work.
Rigidbodies:
- Pro: Physics
- Con: Movement; The character after the key is pressed. Friction is too sluggish, while
Sleep() is very Jolt-like
I'm looking fora way to either apply physics to a Character Controller or implement Character Controller-like movement with a Rigidbody.
Here is a link to the project: RigidBody: GrapplyGameR
Character Controller: GrapplyGame
Answer by imM4TT · Sep 24, 2020 at 12:08 AM
Short answer : You can create a target destination using user's input then you can use the SmoothDamp method to move smoothly towards the target.
Rigidbody rb = GetComponent<Rigidbody>();
Vector3 targetVel = new Vector3();
Vector3 refVel = Vector3.zero;
float smoothVal = .2f; // Higher = 'Smoother'
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVel, ref refVel, smoothVal);
One more thing, how would I implement stair climbing and ramp climbing with a rigidbody.
You could use Raycast or OnCollisionStay and check the side of the collision, in the case there is one on right/left you call a custom method.
Remember to accept answer if your issue has been solved by someone, thanks.
Answer by MomkeyDev · Sep 24, 2020 at 12:33 AM
If you only want to make the rigidbody look smooth, you can use the interpolation setting in rigidbody components.