Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 lam meng chun · Jul 20, 2011 at 06:32 AM · rigidbodycollider

Avoid one gameObject skin in another gameObject

Let say i have two gameObject, one is sphere another is cube. While sphere position is control by mouse cursor(sphere follow the move position). But my sphere will skin in the cube, when my cursor near to cube 1B.

I perfer the sphere will not skin in the cube.

Is Unity3D have any way to make the sphere look like in picutre 1A. The sphere just touch or not skin in the cube like.

I have try add collider and rigidbody, but it is still skin in.

alt text

Update 1

i have a hand model that have animation, i expect the hand can grasp something in the game.(i trigger the hand animation to grasp the object)

But what i got is the hand will skin in the object like 2B, i hope the hand will automatically stop when it touch the object like 2A.

alt text

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by save · Jul 20, 2011 at 06:47 AM

It depends on how you control the sphere. If you use transform.position or transform.translate for positioning you disallow all rigidbody calculations for physic movement. How about attaching a spring joint from an empty gameobject which is controlled by the mouse to the sphere?

Comment
Add comment · Show 3 · 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 lam meng chun · Jul 20, 2011 at 06:51 AM 0
Share

This mean there is no easy way the sphere will automatically stop when touched the cube? It is require coding, can not just simply apply some physics components to make sphere stop when touch the cube.

avatar image save · Jul 20, 2011 at 07:02 AM 0
Share

It wont require much coding if you let the physics take care of the movement, doing this will also be optimized in both visual aspect (as the physics engine is hard to outperform codewise) and for CPU.

avatar image lam meng chun · Jul 20, 2011 at 07:25 AM 0
Share

"How about attaching a spring joint from an empty gameobject which is controlled by the mouse to the sphere". I mostly catch what are you propose to me, it is a great idea. But i'm not so sure how i can implement it. Did you $$anonymous$$d to provide some hint or tutorial source to me? I am still new to Unity 3D.

avatar image
0

Answer by Macdude2 · Jul 20, 2011 at 06:50 AM

What you probably want to do is set up a raycast so the sphere raycasts towards the cube. Then if the distance of the raycast is less than half the width of you sphere, you can translate the position of the sphere away from the cube by .5 - raycast.distance.

Code to put on Sphere:

 var direction: Vector3;
 var hit: RaycastHit;
 var newdist = 0.0;
 
 function Update(){
 direction = transform.TransformDirection(Vector3.right);
 if(Physics.raycast(transform.position, direction, hit)){
    if(hit.distance < .5){
      newdist = .5 - hit.distance;
             transform.translate(-Vector3.right * newdist);
     }
   }
 }
Comment
Add comment · Show 1 · 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 lam meng chun · Jul 20, 2011 at 07:13 AM 0
Share

well, above is just my testing for my other big question. $$anonymous$$ay be i should spell that out also.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Collisions don't work properly 1 Answer

collision child with rigidbody in parent 0 Answers

OnTrigger's Moving Behaviour with Other Triggers 0 Answers

Using character controller insted of normal collider 0 Answers

compount collider or other solution 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