0
\$\begingroup\$

I have recently created a drag drop system where I drag stuff from a UI menu and then drop it to another UI. The child of the draggable UI object is a 3d model. I have attached box collider and rigidbody to this 3d object and moving the Object with rigibody.MovePosition and rigidbody.MoveRotation. The object doesn't respond to physics like if there is a box collider in the way, it just goes through it without showing any physical reactions. I wanted to know if I can do this mixing of Unity UI which helped me in creating this drag drop and also helped scaling the UI and the 3d physics engine to get my job done. My Project is basically an interactable toy train system where user will create a track and run the carts on it. enter image description here

the snake/train follows a spline. and runs on it. Here is a demo https://drive.google.com/open?id=1L_ZTtYqfcJXsvjHmcNaK6gfRHRHio8h4

I am also extensively rotating the object and it's facing forward so that could be an issue ????

\$\endgroup\$
5
  • \$\begingroup\$ Is your UI canvas in World Space mode so that it sits in the same space as your 3D content? Can you show us how you've arranged & configured your UI items in your scene? \$\endgroup\$ – DMGregory Nov 15 '18 at 11:23
  • \$\begingroup\$ yes it's worldspace but does that matter for physical interactions? If so how? also added a screenshot for reference. \$\endgroup\$ – Adnan Nazir Nov 15 '18 at 11:36
  • \$\begingroup\$ It does matter because physics works off of the worldspace position of the interacting objects. Next things to check: can you show us your dragging code? Where do you stop to detect a collision before using MovePosition to say "move to here even if it's in the middle of/on the far side of a collider"? Also, have you tried setting this up without the ScrollView? \$\endgroup\$ – DMGregory Nov 15 '18 at 11:44
  • \$\begingroup\$ I am actually moving the stuff in a spline. I have attached a box collider and rigidbody to the head of train but for it just doesn't interact with collider. I am using the OnDrag and Drop from the IDraggable and IDropHandler Interface. It's the same code from the samples assetstore.unity.com/packages/essentials/unity-samples-ui-25468 Just modified for my requirement. \$\endgroup\$ – Adnan Nazir Nov 15 '18 at 11:52
  • \$\begingroup\$ also added a video clip depicting how it's moving. \$\endgroup\$ – Adnan Nazir Nov 15 '18 at 11:59
1
\$\begingroup\$

Bad of me. I just didn't realize that I am making my rigidbody kinematic. I somehow wandered here and there but didn't look upon that. After making my rigidbody non-kinematic the physical collision, hinge joint and everything started working fine.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.