Instantiate collision

hi,everybody.It is the first post since I settled here.
There is a problem confused me seveal days.It is about Instantiate collision.
A fbx modal which imported from MAX. It turns out through a GUI command and creats by Instantiate:

GameObject obj = Instantiate(Resources.Load("fx")) as GameObject;

What I want is to move objects by listening the movements of mouse. They won’t go through others by detectting collisions.
so, the objects are added codes:

obj.AddComponent("BoxCollider");
obj.AddComponent("Rigidbody");

What a pity! Instantiated objects will keep falling down, so the following code is added:

obj.GetComponent("Rigidbody").rigidbody.useGravity = false;

You see, the objects will detect the collisions perfectly. But, they move on just like in the outer space.What can I do now?

After tests, I found that if the fbx model gragged in the scence rather than by coding Instantiate, they won’t fall down. Why?

How to resolve the problem?
Thanks!

PS: According to the order of the demo which described above, is there any other solutions?
Waiting for your help!

They were falling because you added a rigidbody. When you drag them into the scene, they don’t necessarily have a rigidbody attached.

What you want is to move the item on-screen based on Input.mousePosition. Exactly how far is a little tricky, but that’s usually something you can tweak once you get the connection between Input.mousePosition and transform.position set.

Hi guys,

Sorry for butting in, but is there a best practice to “set the connection” between Input.mousePosition and transform.position? To be able to drag the game object around.

Thanks a lot
Greg

Thank you for your answer!
Well, maybe my English is poor.The exact problem is, the objects can’t detect collision, even it attached a conponent of “BoxCollider” and “Rigidbody”.
I know, it won’t happen a collision without collider or rigidbody.
The conponent of Rigidbody makes the objects fall down, so, I set the useGravary = false.
Now, I need a method to detect the collisions in order to stop the moving of the objects which selected before.

What I want is: 1, Instantiate of objects; 2,click the right button of mouse to select a highlightObject; 3,move the highlightObject according to the movements of mouse; 4,detect the collision during the moving. When collision happens, stop moving.

The three steps of four have already done.

How to change mouse moving into object position changing? The following code:

trans_x = Input.GetAxis("Mouse X") * speed;
trans_y = Input.GetAxis("Mouse Y") * speed;

trans_x *= Time.deltaTime;
trans_y *= Time.deltaTime;

highlightObject.transform.Translate(trans_y * 10000.0f, trans_x * 10000.0f, 0);

Now, collision detect? Headache.

Thanks a lot ybaij!