my situation: I get the mouse position in 3D space while dragging the object, and it should move to this position. The script works very well so far, but it doesn't include collisions with my 4 walls. ( The scene is a small room ) I like the result I get with this script, so rigidbodys and physics do not come into question. Besides, I already tried that with the help of user Tylo. Old question here
Complete Drag script:
Is it possible to set a "drag area" so I can't drag out of the room? I thought of something like this:
Because the object will later be rotated, it would be great if the individual vertices could be read... so no vertice could get out of the room area. Is there a way to get this working? Thanks in advance for your time
I calculate a distance from each of the object corners to the room walls. Is the object been dragged out of the room, I substract the distance, to get it back to the desired drag area. This isn't working with rotation so far. For example, with a cube:
I typically do this with Triggers or Colliders, but you mentioned you wanted to keep rigidbodies out of the picture, yes? I believe even triggers require a rigidbody component.
If your room is perfectly square, then it is simple to limit your drag area. You simply store the values you want to limit, and continually limit them like you do your y-value (but only when you have gone past their limit).
However, that won't stop things like the square from sticking out into the wall, etc. As the object's
I would recommend you still use a rigidbody & invisible colliders to deal with these complex collisions. You can limit how the rigidbody works. You can shut off gravity, make it kinematic, and prevent rotations through physics.
See if that gives you the best of both worlds. If you'd like a run-through on the anatomy of a rigidbody, you can visit a tutorial I wrote here: Rigidbodies Revisited
Also, here is the Docs on Rigidbodies from Unity. Worth a read: Rigidbody Component