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
0
Question by codeguyross1 · Dec 07, 2012 at 03:45 PM · c#collisionrigidbodyprimitive

Force a script generated primitive to test for collision

Hello,

I have a primitive sphere with a rigidbody and a script that creates a primitive square and adds a rigidbody to the created square. The square is generated already colliding with the sphere and both primitives have there rigidbodyconstraints set to freeze all so they will move move on collision.

How do I force the objects to test if they are colliding when the square is finished being generated?

Comment
Add comment · Show 1
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 codeguyross1 · Dec 07, 2012 at 08:17 PM 0
Share

If it helps I am using the following line to create the primitive:

 GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);

I am using the following commands to create the rigid body for the new object:

 Rigidbody gRigid = obj.AddComponent<Rigidbody>();
 gRigid.constraints = RigidbodyConstraints.FreezeAll;

and the code to position the created primitive:

     Bounds bounds = renderer.bounds
     obj.transform.localPosition = new Vector3(bounds.center.x , bounds.center.y, 
     bounds.center.z);

This code is called inside the sphere.

2 Replies

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

Answer by codeguyross1 · Dec 07, 2012 at 09:42 PM

I figured out a way to do this using instantiate instead of the way I was creating the primitive before. The command is

 Instantiate (spawnedCube, new Vector3(obj.transform.position.x, obj.transform.position.y, obj.transform.position.z), Quaternion.identity);

obj is the parent object. In this case, my sphere.

Hope this helps someone when testing collisions out in unity!

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 skalev · Dec 07, 2012 at 04:33 PM

if you have everything set to freeze, they won't move. The physics engine will do the collision checks for you as soon as the object is created.

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 codeguyross1 · Dec 07, 2012 at 08:05 PM 0
Share

I would think this also but it doesn't seem to do the check unless one of the objects move. I can use the gizmo in the scene view to move the object. Any idea how I would check collision between the two objects without moving either of them?

avatar image skalev · Dec 07, 2012 at 08:47 PM 0
Share

gRigid.constraints = RigidbodyConstraints.FreezeAll;

First of all this line means it won't move any how, you should comment that out.

If after you correct that, they still don't collide, then my guess is that collisions will only be calculated if one of the objects move. otherwise it makes no sense in a physics world.

I'm not sure what you are trying to achieve, if you explain the broader picture it might be more clear.

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

10 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

Related Questions

Objects with colliders going through walls and each other. 3 Answers

Prevent a specific RB to influence another, but still collide with everything 0 Answers

The object of type 'Rigidbody' has been destroyed but you are still trying to access it. 2 Answers

Rigidbody collision is delayed[FIXED] 0 Answers

Need help with scripting bug fix. pleease 0 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