- Home /
How to fix stuttering when a gameObject´s position should be at a exact place each frame?
So am editing the question to be more specific. This is what I want to prevent:
The object is going through, and I can´t use the physics system to prevent it since everything has fixed positions and nothing is affected by physics. So I´ve already solved this, but not very well. Because the objects are moving fast (or skipping positions in space) the collisions are detected late. I was asking if there was a way of lerping in between frames in order to not skip positions and be accurate, because this only works if it´s moving slow.
So there are 3 steps in this process: get the currentTotalX (sum of grounds width) += 0.1f (this number changes depending on how much should increase/decrease); Then instantly setting their scales to this float scaleX = (currentTotalX - GetSumGrounds(groundBases) - cornerX) / sumPercentageGround * percentageGround[i] / originalGrounds[i]; It´s a little confusing, but it´s basically getting their scales based on percentage and the currentTotalX I mentioned. When that value decreases, so does this. Then just instantly positionate them to be aligned and look like a single ground.
So here is the issue. The scales, currentTotalX and the positions are directly set instead of lerping. And because the positions depend on the scale and the scale on the currentTotalX I don´t know what to do. I tried lerping the scales and the currentTotalX, but nothing worked.
So the blue box is moving right, it hits the red box... goes through it, but you want the blue box to stop and align the edges with the red box? Does those boxes have triggers on them or anything? Is the movement a fixed position you are going to? Or you just move it till it contacts something?
Yes, it´s supposed to stop moving when hits the red box. When it collides, the white ground below clamps its scale, so the blue grounds around them stop moving (since their positions are fixed to be always at their sides). They don´t have triggers: I know that they are colliding because of the blue and green raycasts. Like I said, the scales of the white grounds instantly change depending on the currentTotalX, but if they scale slowly this doesn´t happen.
I have an interesting idea using a trigger. I find it a little much to raycast out the sides. Let me know if you want to see it.
Answer by Vega4Life · Dec 07, 2018 at 09:19 PM
This is an oldie, but has good information. It should satisfy any lerping needs.
https://chicounity3d.wordpress.com/2014/05/23/how-to-lerp-like-a-pro/
Sorry, I don´t know if I read something wrong or if that site doesn´t really answer the question; but I think it doesn´t even mention lerping between frames.
I am not sure what you mean by lerping between a frame... that's not a thing.
I mean moving from the position of frame 1 to the position of frame 2 at the deltaTime of frame 2. But because I don´t know which will be the next position, it´s more like directly setting the position of this frame, but moving smoothly to it from previous position. $$anonymous$$aking an instant change in position, but smoothly. I know that an instant change by definition doesn´t take time, but that was the reason I wanted to lerp in between frames.
Your answer
Follow this Question
Related Questions
Time.deltaTime making color lerp appear fast, but won't reach 1 1 Answer
Jump with mathf.lerp problem 2 Answers
Beginner question about using deltaTime 1 Answer
Camera Stutter on RayCast Collision Problem 0 Answers
Lerp stopping/not working? 1 Answer