So, even though it’s a really simple task, I simply cannot do it. Basically, I have several cubes of scale (1, 1, 1) and with rigidbodies and colliders attached. I want to move them as if they were in a grid, meaning that I want to move them either left, right, up or down by exactly 1 square. Translated, it would be transform.position + Vector3.left/right/forward/back. However, I cannot find a way to move them while still colliding. I mean that, if I have cube A right to the left of cube B, and I want to move cube B to the left, no matter what I do it passes through cube A. And I don’t want to.
float speed = 7f;
target = transform.position + Vector3.left; //or right, or forward, or back, depending on the Input
void MoveTo(Vector3 target)
{
float t = 0;
while (t <= 1)
{
t += Time.fixedDeltaTime / speed;
rb.MovePosition(Vector3.Lerp(transform.position, target, t));
}
}
I tried with rigidbody.velocity, but can’t figure it out. ALso I think with translate doesn;t work, as translate i think ignores colliders. Please, anything that could work is highly appreciated, I am stuck