Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 superventure · Apr 17, 2011 at 03:34 PM · triggerpickupcollideequip

How to set up items- triggers with rigidbodies

Okay, so I have some items that the player can pickup/drop. I need the items to be 'pickupable' just on triggerstay, and be dropped (and fall to the floor) on key press.

I have a box collider set to trigger on the item so that I can pick it up, but how do add a rigidbody and another collider so that it has gravity? I tried just that- adding another box and rigidbody, but then I can't pick it up anymore. I also tried to add an empty child object with a box collider intead so that I could have a rigidbody, but I still couldn't pick it up anymore. I thought it was because the new pysical collider was bigger than the trigger box, but even after making the pysics box smaller, no go.

How can I set this up?

Also, I need the physical box collider to be disabled when held- the player is blocked from moving properly when holding another box collider in their hand

thanks for any help!

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
2

Answer by superventure · Apr 17, 2011 at 05:33 PM

The moving trigger problem is very weird...and ANNOYING. Thanks guys for your help. I guess I am stubborn though, because I found a work around for a moving trigger:

If you want an object to both be a trigger and have pysics, You can have two colliders: the first collider must not be set to a trigger, then add your rigidbody, then add a second trigger(I used a sphere collider) and make it envelope the first collider, and set THAT to a trigger. For some reason, if you mess up that order of operations, the trigger will not be recognized anymore by the engine.

On a side note, the item when held was blocking movement to the player because of the active boxcollider. I tried to set it to a trigger just when equipped (and vise a versa when dropped), but again for some reason, it would only work one time only. SSOOOOO...

I dropped setting it to a trigger/not and added this bit of code

function Start() { ignoreCollision("Player"); }

function ignoreCollision(tag: String) {
var objects = GameObject.FindGameObjectsWithTag(tag);
for (o in objects) { if (o.GetComponent("Collider") && o != gameObject) Physics.IgnoreCollision(collider, o.collider);
} }

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 greysonwarnerbuilt · Apr 20 at 10:13 AM 0
Share

THIS IS THE ANSWER I WAS LOOKING FOR. Thank you holy crap. I thought I was going insane. Why doesn't the original collider work? Why is the order important? I am too new to this and I don't understand. Either way, thank you for posting this.

avatar image
1

Answer by Statement · Apr 17, 2011 at 03:39 PM

There are problems with moving triggers not sending trigger messages, so my suggestion would be to use OnCollisionEnter instead. If you are stubborn still, try making a child object that has the trigger. But I doubt you'll get it working. It will work in some cases (such as something walking into the trigger) but not in other cases (such as the trigger "walking into" something).

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 superventure · Apr 17, 2011 at 03:49 PM 0
Share

Aw man, I was hoping that was not the case. Oh well. I just tried function OnCollisionStay(other:Collision){ thought, with the same results- am I setting that up right? Do I still have to have something set to trigger too?

avatar image Statement · Apr 17, 2011 at 04:03 PM 0
Share

I'd ditch the trigger entirely, if possible. However I find it a bit inconvenient too since sometimes you want to have an area of effect. In that case you could possibly do with Physics.OverlapSphere et.c.

avatar image Statement · Apr 17, 2011 at 04:05 PM 0
Share

Though I may be mistaken about the trigger not sending messages. I was using child triggers on character controllers for AoE behavior, but it didn't work. It only worked when someone walked into the trigger, not the other way around. It is possible (though I would be surprised if it was the case) that it would behave differently when parented to a rigidbody. Should be simple enough to set up a test on this.

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

1 Person is following this question.

avatar image

Related Questions

trouble with parenting 1 Answer

GUI text like GTA 2 Answers

Destroy trigger after a certain time 2 Answers

Load next level when reach score 1 Answer

Touch the same GUITexture button to Pick Up and Drop a Rigidbody Game Object 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