- Home /
Does anyone know how to create sliding movement?
I'm trying to create a slide where you slide for 1.5 seconds then it stops after that 1.5 seconds, anyone knows how to do that? I'm using the rb.velocity method for movement and jumping.
Im trying to make the movement smooth because I found a method which is rb.addforce(rb.transform.position * slideForce) but the movement is pretty lag, like you instantly teleport.
Answer by theterrificjd · Jul 26, 2020 at 11:53 AM
What you can do is grab the Physics Material that is being used on the mesh colliders the player will be in contact with (you may need to create a new Physics Material for this) in a script, and run a co-routine to interpolate the friction from 0 back to the original.
Basically:
IEnumerator Slip() {
regularFriction = physMat.friction;
yield return new WaitForSeconds(.02f);
if(timer < time) {
timer += .02f;
}
if(timer >= time) {
timer = time;
}
physMat.friction = Mathf.Lerp(0, regularFriction, timer / time);
}
Or, of course, if you don't want it to slowly bring the friction back, you can just
IEnumerator Slip() {
regularFriction = physMat.friction;
physMat.friction = 0;
yield return new WaitForSeconds(1.5f);
physMat.friction = regularFriction;
}
Hope that helps.
I'll try using this code and do my own changes, thanks and take care.
Your answer
Follow this Question
Related Questions
Why is my Player sliding in one direction? 1 Answer
How do I increase the speed of my rigidbody after going down the slope 3 Answers
How can i rotate the camera with the mouse but only when drag ? 0 Answers
Playmaker: How to use and get variables from other visual scripting or C#? 1 Answer
How do I slow down while Im Sliding? 0 Answers