- Home /
How do I make my Player object move around as if it has high drag (with no sliding), but reacts to knock-back forces as if it has low drag (with lots of sliding)?
I'm trying to create this type of effect: http://youtu.be/v2uOGQegj2c?t=25s where, (1) while moving around, your character moves without any sliding (as if there is high drag), (2) when you get hit, your character reacts to the knockback as if it has very low drag, and slides around.
Any suggestion or advice would be appreciated!
Attempts: [1] I've tried one way of using Translate(translateDir), where the Vector3 translateDir= moveVector + knockbackVector3; This didn't work because the knockbackVector3 isn't counteracted by the moveVector, in the same way that rigidbody.Addforce counteracts rigidbody.velocity.
[2] I tried the straight forward rigidbody.AddForce(movement) for movement, and rigidbody.AddForce($$anonymous$$nockbackDir) for knockback. The problem with this is that they are affected by the same drag value on the rigidbody, so if I make the drag value low, both forces will cause the character object to slide a ton (rather than having just the knockback force causing the slide, and have the movement not causing any slide).
[3] I didn't have luck using the rigidbody.Addforce for knockback, and Translate for movement, the translate doesn't counteract the knockback.
So, atm, I still have no idea how to solve this. Please help! :c
Answer by FezAstron · Feb 03, 2015 at 02:50 AM
You can use rigidbody.AddForce(KnockbackDir, ForceMode.Impulse);
or test out other force modes, there is ForceMode.Acceleration
and ForceMode.VelocityChange
Yeah thanks Fez, I tried Acceleration and Velocity change. They didn't affect the sliding aspect unfortunately. They only affected how the force is applied to the rigidbody.
How about applying a physics material that makes you slide when you need it to slide and when the sliding time is over, make the physics material = null or back to the material you might have applied originally? I can help you with the code if you don't know how to change the material through code.
Well, the last thing I can offer you if rigidbody.$$anonymous$$ovePosition which moves the rigidbody just like transform.position except collider's work. I didn't see you mention trying it so just letting you know ;)
Oh and also, you can apply one physics material to it and keep it. Then when you need it to slide, you change the friction properties in that material. This way you keep everything default until sliding is needed, this way, no need to keep switching materials. Just an idea, do whatever you think is best. Good luck!
Your answer
Follow this Question
Related Questions
Moving rigidbodies at random 1 Answer
Implementing Counter-Movement 0 Answers
rigidbody friction problem....HELP!! 1 Answer