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 EClancy · Aug 20, 2014 at 07:05 AM · 2dcollisionrigidbodycollidertrigger

Collider2D/RigidBody2D not working

When searching, I seem to only be able to find people who did not know to use the 2D version of colliders or methods, so it's been difficult to find an answer for this.

I have two objects I want to collide (this game is a top view, so gravity does not come into play here).

When the fireball flies, it goes straight through the player without ever logging a collision. They are both on layer 0. Am I missing something small?

A Fireball: (Note that I have IsTrigger checked, but either way does not seem to make a difference)

Fireball1 My Fireball

And the player (except for it's transform, let me know if that is needed here):

The Player

Here is the code on the fireball:

 var speed : int = 2; 
 
 
 function Update () {
 
     transform.Translate( Vector3(.5,0,0) * Time.deltaTime * 10);
 
 }
 
 function OnCollisionEnter2D(coll: Collision2D) {
     Debug.Log("FIREBALL COLLISION");
     if (coll.gameObject.tag == "Player"){
         coll.gameObject.SendMessage("ApplyDamage", 34);
     }

     Destroy(gameObject);
 }


And here is the code on the player (though I don't think the problem of 2D collision resides here):

 var health = 100;
  
 function ApplyDamage (damage : int) {
      health -= damage;
  
      if(health <= 0) {
          Die();
      }
  }
 function Die () {
    //Die and or Respawn
    Destroy(gameObject);
 }


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 Nexx · Aug 20, 2014 at 07:36 AM 0
Share

Try with removing is$$anonymous$$inematic option from rigidbodies

1 Reply

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

Answer by HarshadK · Aug 20, 2014 at 07:48 AM

Since your Fireball object has a trigger collider you should use OnTriggerEnter2D instead of OnCollisionEnter2D.

Also from your Fireball and Player game object uncheck Is Kinematic since kinematic ridigbodies don't participate in collisions (Ref: Rigidbody2D.isKinematic).

Now since your Fireball and player is not kinematic anymore you should move it using Rigidbody2D.MovePosition from your FixedUpdate() for proper physics.

Something like:

 var speed : Vector2 = Vector2 (2, 0);
 
 function FixedUpdate () {
     rigidbody2D.MovePosition(rigidbody2D.position + speed * Time.deltaTime);
 }


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 EClancy · Aug 20, 2014 at 08:06 PM 0
Share

Perfect, I did what you said and it looks much cleaner and works as intended, except that the fireball does not move in the way it's rotated, so I suppose I will keep using my Vector3 code for now, and try to figure out how to do that properly.

Since they are not kinematic but I do not want gravity to affect them, I turned the gravity scale to 0. Is this the proper way to handle that?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Collision between two kinematic rigidbody triggers 2 Answers

Detect a collision point, but allow pass through collider. 0 Answers

Cirlce Colliders 0 Answers

Can't add Rigidbody component because collision prevents it 2 Answers

Collision returning an error 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