I have a cube. That cube is moved by a script that alters the transform.position. Colliders dont work on it it just goes straight through them. I need a way of limiting the movement of that object. Here is the script that does that part:
Vector3 tp = transform.position;
tp.z = Mathf.Clamp(tp.z, -3.25f, 3.25f);
transform.position = tp;
The problem with this script is that the size of my cube changes (you cut it, you may cut it in half or 1/4th, 1/7th etc.) which means that by getting the transform.position you only limit its movement by the transform, not the shape of it. This means that when it’s beside a wall it stops at certain coordinates instead of when the mesh itself is touching the wall. Would appreciate some help i have been searching for an answer for well over 2 hours without a break.
I should also add that I can’t use OnTrigger because for some reason it messes with other scripts in my project.