- Home /
2D: Can You Detect Sliding ?
Hi, I have a 2D game where the surface that the player stands on with rotate left and right creating a slope. At a certain point the player sprite will start to slide due to gravity/mass/etc.
Is there a way to detect if the player is moving due to a slide? for example, If i want to play a sound of shoes scrapping across a stone floor when the player is sliding.
Maybe I can answer my own question. Is it a matter of checking for velocity > 0 when the directional keys are no being pressed? Or is there a Unity Function something like "OnRigidBody2DSlide()"
Thanks!
Answer by HarshadK · Oct 17, 2014 at 12:41 PM
No there is no such function to detect sliding. You can do it using few condition checks:
See if the player and the platform are in collision with each other. Use OnCollisionStay for this.
Check if your platform is either tilted towards left or right by checking its rotation.
Now check if the velocity of the player is greater than zero.
If all of it is true then the player is sliding.
but what if he's running down the hill? he's not sliding then but these conditions are all true.
You can have a run variable that you can set based on the input from user to make your character run. You can check if the run variable is set or not.
There are lots of conditions that you have to check based on your requirements in order to make sure he is really sliding. :-)
Your answer
Follow this Question
Related Questions
Pushed objects randomly sliding into walls 0 Answers
How to make a 2D character stop sliding? 2 Answers
2D Animation does not start 1 Answer