Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ashjack · Nov 27, 2013 at 01:23 PM · c#collisionrigidbodycolliderdrag

Objects with colliders going through walls and each other.

I have a script that enables the player to drag objects around in the scene. But even though these objects have colliders and Rigidbodies, they still go through walls and each other. Here is my script:

 using UnityEngine;
 using System.Collections;
 
 
 public class mouseDrag : MonoBehaviour {
 
 void OnMouseDrag()
     {
        float distance_to_screen = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
        transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen ));
  
     }
  
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Gruffy · Nov 27, 2013 at 01:41 PM

Basically i think from what you`ve said is that your rigidbody is updating later than your repositioning of the mouse, which would be about right...

You see RigidBody updates in FixedUpdate (once for every 2 frame updates)(this is Unity`s special physics update method) OnMouseDrag is updating every "Update" method frame.(so , it is updating twice as fast as your rigidbody)

Basically you are reaching a point in space using mouse and applying that translation to your object, your problem is rigidbody is trying to catch up with everything you just did inside a method that is twice as slow as "Update".

Suggestions: (not recommended) Either rethink your approach.

(Recommended) In Unity 3D, there come a script in the standard assets packages that can be imported by right clicking the mouse inside your Project browser and selecting "Import New Asset"

scroll down the list and find the Unity scripts packages.

Inside your project`s "Standard Assets" folder view in Unity3D, once imported, is a script named DragRigidBody.js.

This will ultimately be the droid your looking for! Apply the script in the same way as you have done so to your previous attempt. Read the the comments in the script to see what it`s doing and how its handling what you were trying to achieve

btw, This has been answered before Here

Take care and good luck.

If this helped to solve it for you , then mark it as answer if you can so others can benefit from it too :)

Gruffy

:)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ashjack · Nov 28, 2013 at 07:36 PM 0
Share

I have replaced mousDrag.cs with DragRigidbody.js, and it does nothing when I drag. What do I do?

avatar image ashjack · Nov 28, 2013 at 07:47 PM 0
Share

O$$anonymous$$, I worked it out, the parts can't be set to kinematic. Is there a way I can keep the collision in, but not push away the object it collides with (In this case another building block)

avatar image
2

Answer by Subhajit-Nath · Nov 27, 2013 at 01:41 PM

When using Rigidbody, don't manipulate transform directly. Use rigidbody.MovePosition instead. Hope this helps.

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.MovePosition.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ashjack · Nov 28, 2013 at 08:55 PM

Sorry to keep bothering you, but I figured that out too. I added into the script that disables mouse orbit when a brick is being dragged a bit that makes bricks kinematic if they are not being dragged. I don't need any more help now, and thanks for showing me the script!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Stop sword from distorting character animation 3 Answers

Getting a sword in place while attacking an enemy 3 Answers

Why object goes sometimes through walls by adding force ? 2 Answers

Trouble with Physics.IgnoreCollision 0 Answers

Unwanted jittery behavior 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges