- Home /
Vector3 is always subject to serious stutter in Translation
Hello,
Regardless if it's the Rigidbody gravity straight from unity, or my own scripted gravity, there's always a bit of stutter.
My current code is : void translateUnit() {
if (gravity.isGrounded) //If the unit is grounded
{
Ray ray = new Ray(transform.position,Vector3.forward); //Make a ray shoot foward **Change Eventually**
RaycastHit hit;
if (!Physics.Raycast (ray, out hit, _groundedRayDistance)) //Cast the ray in the movement direction
{
parent.parentObject.transform.Translate((_movementVector ) * 2); //Move if there wasn't a hit
}
else
{
}
}
else
{
_movementVector.y = gravity.gravity;
parent.parentObject.transform.Translate(_movementVector);
}
}
Gravity is set to 9.81 for the time being. The problem that if I move in any direction while falling straight down, my character goes down for one frame, and then in the direction for the next frame, and then down again, and then in the direction again.
I thought by merging all of the Vector3s together into one simple movement direction it would fix this issue.
Moreover: My input is in Update() in another controller script, and this is in FixedUpdate.
I've added Coroutines to slow down my grounded and gravity calculation as well, but they didn't do anything except slow down the recognition of grounded and gravity / sometimes exacerbate the problem.
Also, I'm using my own character controller script; just the gravity that's pretty ridiculous to get down.
Thanks for any help!
This may or may not be the issue, but I believe FixedUpdate() should be used only for physics calculations so if you're moving your controller in this function, it will definetly stutter. Try placing your controller in Update() and multiply the movement by Time.deltaTime.
Rabwin- thank you! I didn't realize this has been the problem in my project. CharacterController related adjustments should be in Update and not FixedUpdate... of course!
Thanks for the suggestion.
I just changed it and it's the same exact problem, though.
Since I have a rigidbody attached to my unit I figured that I would have to use LateUpdate, but then I read somewhere that for the type of calculation I was trying to do FixedUpdate -might- be better. Then I removed the rigidbody and put it in the Fixed and Late with the same problems.
No matter where I put the method it always stutters.
On the rigidbody, try setting it to Interpolation (this should always be used on bodies that have a camera attached, afaik)
I set it to both interpolate and extrapolate and re-assigned the method to fixed late and update. The only thing that happened was Extrapolate was very stuttered.
If you guys know of any solutions please post them, but at the moment I'm going to spend a few hours/days building up my Rigidbody script. I have no "air" lag with my smooth jump algorithm, so I'm going to try to extend that to go along with falling off of smallish objects. If it works out I'll post the scripts in a project, as this is a recurring problem for a lot of people it seems.