Setting is 2D.
Box has 2dcollider and rigidbody kinematic = true.
Box is falling automatically(scripted), although I can press down to move it faster than scripted.
All my movement use Vector3.Lerp, coded in this format:
transform.position = Vector3.Lerp (transform.position, targetPos, t);
I decided to do without physics so falling boxes will just stack over and not bounce around, slide or move sideways ( especially when hit by another box sideways).
my initial goal to let them stack over each other is working. I put a raycast2d in the box.
if(hit){
if (hit.collider.tag == "box") {
canControl = false;
canMove = false;
//spawn a new box
canSpawn();
}
} else {
//when is is hitting nothing anymore, it will continue it journey downward.
canMove = true;
}
Problem: When I press down, the box pass through other boxes and not stop at the top of the box.
Is Lerp the problem here?That is, when the box moves using lerp from point A to B, it does not really traverse the points between A and B, hence when a box is positioned between point A and B, the moving box that has a raycast will not hit the box?
And if so, what movement should I do?