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 GameGuy · Apr 09, 2012 at 08:11 PM · collisiontimenoobparenting

Parenting after X time with collision, I dont get it!

Hey,

I need help with parenting an Object to an other after a collision occurred for a specified amount of time generally spoken. I will try to explain it more detailed, but first I want to let you know that I´am trying this for a few days now and I don´t get it working properly.

We have Object A, this is a moving Prefab and we have Object B it has a collider and a script that should wait for collision with Object A, and if the collision is happening for the amount of X time Object B should become the parent of Object A. If A and B are colliding for a lower time than X no parenting should happen.

alt text

-Yeah, sounds simple but not for me I really don´t get it working, I have not much programming knowledge and I think I´am missing a basic programming concept. I wrote a lot of diffrent scripts the last days but none of them worked properly, and I know most of you do not respond to Questions that have no scripts attached but I want to understand(!) not guess what is right so please help.

Thanks in advance for the time you invest,

GameGuy

problem_visual.png (17.8 kB)
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

1 Reply

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

Answer by by0log1c · Apr 09, 2012 at 08:33 PM

This is a simple example that should do what you need. You could use OnTriggerEnter and OnTriggerExit instead of a constantly running checks in OnCollisionStay but this is more informative than actual implementation. This pseudo-code is not performance-friendly, but perhaps it'll give you hints.

 public float collisionRequired = 2.5f;
 private float collisionCurrent = 0.0f;
 
 function OnCollisionStay(Collider coll)
 {
     collisionCurrent += Time.deltaTime;

     if(collisionCurrent > collisionRequired)
         if(coll.transform.parent != transform)
             coll.transform.parent = transform;
 }
Comment
Add comment · Show 4 · 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 GameGuy · Apr 09, 2012 at 09:42 PM 0
Share
  • and BIG THAN$$anonymous$$S BY0LOG1C, I turned your pseudo-code into working-code :) , and it does what i was not able to do! Please let me ask one more thing is it possible that code like that is not working with really small amounts of time?

avatar image by0log1c · Apr 09, 2012 at 10:38 PM 1
Share

Well, I know physics is calculated by tick at interval. Would an object goes in and out the collider in-between ticks, it would go unnoticed. If you have a rigidbody, setting it to Continuous Dynamic collision detection would help, but that's a known (hardly fixable) issue.

avatar image by0log1c · Apr 09, 2012 at 10:40 PM 0
Share

BTW, I hate to request thumbs-up but the norm on UA is typically to mark an answer as accepted once a question is solved.

avatar image GameGuy · Apr 09, 2012 at 11:48 PM 0
Share

$$anonymous$$akes sense if the physics step is actually higher than the required collision time. Thanks again for your help!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make a sound play and have a delay after so it can't be activated again very fast? 1 Answer

Collision between Character Controller and another object sends other object flying 1 Answer

Make something change color for a set amount of time 3 Answers

No collision between objects connected by fixed joints 0 Answers

Is it a bad practice to change the timescale for the whole game? 1 Answer


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