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 Ekta-Mehta-D · Mar 11, 2013 at 05:35 AM · collisioncolliderscollisiondetectionspherecollider

Collision between two sphere game object

In my game scenario , i have two sphere game object. In that i have one sphere game object is on statis position and other sphere game object is used as bullet. For that i have created prefab of sphere game object. And i have put empty game object in my 2D scene and instantiate my bullet prefabe on that empty game object position.

Now when i shoot bullet i want to detect collision. I have tried so many methods but none of them works for me.

My code:

 function Update ()
 {
  
     var spawnPoint : GameObject = GameObject.Find("Bullet");
   
     if(Input.GetMouseButtonDown(0))     
     {     
          if(spawnPoint != null)
          {
               var hit  : RaycastHit ;
               var ray : Ray  = Camera .main .ScreenPointToRay (Input .mousePosition );
               if(Physics.Raycast (ray, hit))
               {     
                        
                        shootProjectile = Instantiate(bulletSphere, spawnPoint.transform.position,spawnPoint.transform.rotation);
                      shootProjectile.rigidbody.useGravity = false;
                      var tempx = hit.transform.position.x;
                      var tempy  = hit.transform.position.y;
                    
                      shootProjectile.rigidbody.AddForce (shootProjectile.transform.TransformDirection(new Vector3(tempx,tempy,0) * 8000 * Time.deltaTime));        
                      //if(hit.collider.gameObject.tag == "Enemy")
 //                     {
 //                         Destroy(hit.collider.gameObject);
 //                     }                 
                      
               }    
          }
      }
 }

Method i have tried :

OnControllerColliderHit (hit : ControllerColliderHit)

OnCollisionEnter(other : Collision )

Which collision matrix do i need to use?

please please help me to solve my this problem. Thanks in advance. :-(

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
0

Answer by robertbu · Mar 11, 2013 at 07:59 AM

I'm not sure what you have your mass set at for your bullets, but if it is 2.0 or below, a force of 8000 is going to sent it bulleting (pun intended) out of the gun. The problem is that for the bullet to collide, the bullet and the collider must be at the same place. With something moving so fast, it is highly likely that between one collision test and the next it will start out in front of the object and then be behind the object without ever touching the collider.

A couple things you can try:

  • Cut the force. If you have a mass of 1, try cutting the force you apply to 4000, or even 2000.

  • Change the collision detection on the rigidbody to Continuous or Continuous Dynamic.

And you want OnCollisionEnter()

Comment
Add comment · Show 2 · 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 Ekta-Mehta-D · Mar 11, 2013 at 08:59 AM 0
Share

i have changed the force.. but still OnCollisionEnter() is not called.. And i have kept rigidbody to bullet only, not with target sphere.

avatar image Ekta-Mehta-D · Mar 11, 2013 at 09:45 AM 0
Share

it's ok sir.. my problem has been solved. Thanks for your reply and help. Have used OntriggerEnter() method.

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

10 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

Related Questions

How to make a certain function if an object collides with another object? Been searching it up for 2 months. 1 Answer

A node in a childnode? 1 Answer

2 small spheres colliding not sending trigger 3 Answers

Find axis of collision 0 Answers

reset level on collision 3 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