- Home /
How to get transform.Translate to work with rigidbodies
Ok so I am moving the player via transform.Translate for a third person platformer. And I have a rigidbody attached to the player only for the collisions, and add force.
When I use transform.Translate, the wall collisions are jittery. Which makes sense since transform.Translate doesn't respect the rigidbody physics.
So I tried to switch my movement to AddRelativeForce() but I was running into speed cap issues and most importantly, lots of sliding (which again, makes complete sense). And for a third person platformer slipperiness doesn't work well (unless you were on ice I guess).
I really like using transform.Translate for the precision, is there any way I could continue using it while keeping rigidbody physics intact? So far, I'm not seeing any other way to do it within the rigidbody physics :/
Thanks in advance! Actual code is appreciated!
Also here is the translate code:
//adjust is a value that moves the player over slants and slopes
//accel goes up to 20f
//horizontal is the joystick input
transform.Translate (new Vector3(0f,adjust,1f) * accel * horizontal * Time.deltaTime);
Answer by meat5000 · Jul 03, 2015 at 10:22 PM
You cant use Translate when moving a rigidbody for collisions. It teleports.
If you dont want to manipulate force or velocity try MovePosition
Alright so I'm trying $$anonymous$$ovePosition and its working fairly well. I'm still getting the jittery wall collision wall though. Is there some sort of raycast or capsulecast that I could do to fix the jitter? I switched all my loops to FixedUpdate() ins$$anonymous$$d of Update() and that seems to help. $$anonymous$$y camera now works a little better than it did before all this so thats a plus. Thanks for your help so far!
Answer by Cherno · Jul 03, 2015 at 11:05 PM
I never had a problem with moving rigidbodies via Translate. I largely followed this tutorial:
https://www.packtpub.com/books/content/unity-3x-scripting-character-controller-versus-rigidbody