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 /
  • Help Room /
avatar image
0
Question by Havax · Dec 16, 2016 at 12:35 AM · rigidbodycollidercolliderstransform.positionpickup

How to prevent object from entering other colliders

I have a script that allows my player to pick up objects, if it meets a certain criteria:

     public void Pickup(GameObject item) {
         items = item.GetComponent<Renderer> ();
         theitem = item;
         ObjectSize = items.bounds.size.magnitude;
 
         carried = true;
 
     }
 
     // Update is called once per frame
     void Update () {
         if (carried) {
         newitempos = gameObject.transform.position + Camera.main.transform.forward * range;
         theitem.transform.position = newitempos;
 
             if (Input.GetKeyUp(KeyCode.Mouse1)) {
                 carried = false;
                 theitem.GetComponent<Rigidbody> ().velocity = Vector3.zero;
             }
         }
         
     }

However, since the object's motion is locked when it is being carried, it ends up going through other object's colliders, that are too heavy to move, or aren't allowed to move at all. I need a way to prevent this without causing too much work on the system.

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 Havax · Dec 16, 2016 at 04:55 AM 0
Share

Bump**

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kkiniaes · Dec 16, 2016 at 05:37 AM

This answer is based on the fact that your game sounds like a FPS; one thing that many games do is render objects that are being held by the main player on a separate camera that renders on top of everything else. This ensures that you can always see the item, and that it never accidentally culls with the environment.

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 Havax · Dec 17, 2016 at 01:02 AM 0
Share

This is somewhat effective, however, it doesn't eli$$anonymous$$ate the player's ability to move that object through the collider. I am still able to pick up objects, and move them outside of walls- meaning the player completely loses the object. It is also difficult to perceive the depth at which your item is at, to be able to accurately place it somewhere.

avatar image kkiniaes Havax · Dec 17, 2016 at 02:45 AM 1
Share

That's a good point, in that case you could have a script attached to the object that has an OnCollisionEnter implementation that can send a message back to the player indicating that it has entered a world collider.

You could also try to take advantage of the fact that when you child an object to a parent rigidbody, it's collision box is added to the bodys' collision system. In other words if the child has a collision box and the parent has a rigidbody, it will treat the childs collider as part of the total collider.

avatar image Havax kkiniaes · Dec 17, 2016 at 03:06 AM 0
Share

I've thought of the OnCollisionEnter idea, but having every gameobject in my scene that's 'movable' execute a script that's constantly checking for collisions seems like an unnecessary hassle and a lot of work for the system. However, I did attempt your second suggestion, and while it didn't fix the problem, it did fix another problem I was having- Thank you.

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

107 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody wont move after changing collider.bounds.center 0 Answers

Child gameObject with collider not colliding if parent has rigidBody 2 Answers

Object passes through other moving objects 1 Answer

(With picture) Platformer jumping and land problem - character goes into ground and then gets pushed back out 0 Answers

NEED HELP!!! How to explode my enemy ship? Need help with C# script 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