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
1
Question by JNetRocks1316 · Mar 09, 2014 at 06:58 AM · collisionphysicscollidertrigger

Collission and Trigger on Same object

So I'm working on creating like a health-orb pickup item. I need the orb itself to have physics detection so it bounces on the ground, but I also need a trigger to tell if the player is near enough to pick it up (but not directly on top of it, I want the orbs to sort of 'float' to the player if they're near enough).

So I've been doing some research and I'm a bit confused on the topic. From what I gather you can only have one collider of each type on a single game object (one box, one sphere, etc.) and multiple colliders will be treated as a compound collider. So you can only have a single game object as either physics or trigger.

So I created a parent game object that had a sphere collider to detect physics (works fine!) Then I created a child object with a sphere collider at a much larger scale with a trigger and script attached.

However, the child sphere seems to be having a physics reaction with the player where it 'pushes' them back a bit, even though it's sphere is set to trigger only.

So then I tried unparenting the child and the same thing still happens where the is-trigger sphere is causing my player to 'push' back.

I'm confused on what's causing this!

Edit:

I kept playing with this and decided since I couldn't get the previous way to work that I would create it as a single gameObject. So I have a sphere with a rigidbody and collider which behaves as normal and then a script to check for distance (instead of a trigger).

However, when I get to the point where I move the item it still has the same issue where it sorta pushes the player.

I even set them on Physics layers where they ignore eachother.

I'm at a loss with why this is happening!

the health-orb Update: (placed on a gameobject with a rigidbody and sphere collider)

     void Update(){
         //Rotate this item to face the player at all times
         transform.LookAt(transform.position + Camera.main.transform.rotation * Vector3.back,
                          Camera.main.transform.rotation * Vector3.up);
 
         //Keep track of how far the item is from Snow
         distanceSnow = Vector3.Distance(transform.position, snow.transform.position);
 
         RaycastHit hitInfo;
         //If the player hasn't reached the orb, reduce it's lifespan
         if(!absorbing){
             if(Physics.Raycast (transform.position, -Vector3.up, out hitInfo)){
                 if(hitInfo.distance <= 0.04)
                     checkingDistance = true;
                     //delay a moment before checking for distance
             }
             if(checkingDistance){
                 if(distanceSnow <= pickupRange){
                     absorbing = true;
                 }
                 lifespan -= Time.deltaTime;
                 if (lifespan <= 0)
                     Death();
             }
         } else {
             //If the player has neared the orb start floating towards the player
             this.rigidbody.isKinematic = true;
             speed += speedIncrease;
             speed = Mathf.Clamp (speed, 0, 6);
             float step = speed * Time.deltaTime;
             transform.position = Vector3.MoveTowards(transform.position,
                                     new Vector3(snow.transform.position.x,
                                     snow.transform.position.y + 0.25f,
                                     snow.transform.position.z), step);
         
             if(distanceSnow <= 0.26f)
                 GrantCP();
         }
     }

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 HuM4NoiD · Nov 12, 2020 at 04:33 PM 0
Share

Let me know if you managed to find a solution to your problem.

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

How do I detect when two CharacterControllers collide? 0 Answers

overlapsphere to destroy NPCs on exit 1 Answer

Prevent shooting when gun is inside wall 1 Answer

Trigger Colliders: Is there a way to simulate a non-trigger collider? 0 Answers

How do i get OnTriggerStay2D to work? 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