• 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 Alienjesus · Apr 05, 2011 at 07:11 PM · collidertriggerparentrigidbodiesinherited-members

When collider enters trigger, colliders parent = triggers parent

I'm trying to write some code so that when a gameObject enters a Trigger, it parents that gameObject to the triggers own parent. However, I'm having some difficulty accessing the Transform of said object in my code. Here's some examples of what I've tried:

function OnTriggerEnter (other : Collider){
if (other.transform.tag == "Moveable")
    {
    other.transform.parent = transform.parent;
}
}

And:

var otherTrans; function OnTriggerEnter (other : Collider){

if (other.transform.tag == "Moveable") { otherTrans = other.transform;
otherTrans.parent = transform.parent;

} }

I've tried a few other things too, but they're all variations on this. I've tried looking through the script references for inherited members, but I still can't find a way. What is the exact set of inherited members I need, or does my code need changed?

Thanks

P.S. all the colliders which it would pick up are rigidbodies.

Comment
Add comment · Show 2
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 xCRKx TyPHooN · Apr 05, 2011 at 07:19 PM 0
Share

Would otherTrans.parent.gameObject = transform.parent.gameObject be what you are looking for?

avatar image Alienjesus · Apr 05, 2011 at 07:41 PM 0
Share

Unfortunately not.

1 Reply

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

Answer by Eric5h5 · Apr 05, 2011 at 07:26 PM

Your first code example will work as-is, although you don't need to get the tag from the transform component (it's inherited from GameObject anyway), and using CompareTag is better.

if (other.CompareTag("Moveable")) {

Put Debug.Log statements in to see if the trigger event is happening, and what the other's tag actually is.

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 Alienjesus · Apr 05, 2011 at 07:40 PM 0
Share

It's not picking up the colliders entering the trigger. I seem to have a terrible record with triggers, they never seem to work for me. Evidently I'm doing something wrong with them.

I thought it was as simple as if a collider enters the trigger, it sends the message that starts the function?

avatar image Eric5h5 · Apr 05, 2011 at 08:21 PM 0
Share

@Alienjesus: Have you looked at the chart here? http://unity3d.com/support/documentation/Components/class-$$anonymous$$eshCollider.html Not everything generates trigger messages.

avatar image Alienjesus · Apr 05, 2011 at 09:16 PM 0
Share

But in this case, a static trigger is colliding with a rigidbody collider, so it should.

avatar image Alienjesus · Apr 09, 2011 at 03:47 PM 0
Share

Changed the trigger to a kinematic rigidbody trigger, everything works fine now.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to prevent a game object from colliding with its parent 2 Answers

Can't click gameobject when over another trigger? 1 Answer

Multiple triggers on one object 7 Answers

Reaching a gameobject from its collider 3 Answers

Parent Script accessing Child components 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges