Pigeon shit

[ Pigeon shit ] Unity doesn’t like lerping an moving object

PigeonShit_ThumbSmall So I was working on the controls on the player object (the pigeon shit that’s falling down). We made the decision to disable gravity and handle all physics through code. Why we chose this was because we wanted to have total control over the object so that it does exactly what we want it to do. This way without a rigid-body we don’t have to work with applying force to move it forward/side wards with which you don’t know where it will end up exactly. However a problem that came with this decision was that unity doesn’t like it when you do a linear interpolation(lerp) on a moving object.

(problem) The idea was that the pigeon shit is falling down, so the object has to move down on the y-axis(vertical) constantly, this is a transform. Meanwhile the pigeon shit will have influence from  player-input and the game itself. This happens on the x-axis (horizontal) and is a lerp . So what happened is that when you’re moving the object down and do a sideways lerp it would do the lerp and stop falling down (meanwhile in code the y-position is still going down), when finished with the lerp it would teleport to the in code y-position and continue falling down. This looks very weird and is thus unusable.

(chosen solution) what I did to solve this was to separate the transform from the lerp by making a empty game-object on which you apply the sideways lerp on and where the player-object listens to and copies the x-axis from. The result is a very smooth lerp while falling down :)

Looking back at it of course it wouldn’t have worked. A linear interpolation is finding a value that is some % between value A and B, and in out game it is used to move an object from A to B in a given time-frame. What is important is that the point to which he has to move to is set at the lerp start. Meanwhile the player object is moving down and thus the position changes and the lerp-to position is not correct anymore. What I could have done was to update the lerp-to position on every game update but whether that works is something for another time.