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 disband85 · Dec 09, 2010 at 02:41 AM · 2dcollisioncolliderspritedetection

Collision detection not working properly with 2D sprites

Hey all,

I'm trying to get collision detection working for sprites (I'm using SM2).

Both sprites have a Box Collider. I have ticked 'Is Trigger' for both of them. I have set X and Y to the width and height of the sprite for both of them, and set Z to 3 just so it has some sort of thickness.

One of the sprites has a rigid body. I unticked 'Use Gravity' and left the other settings as default.

Here is my code in the script that's attached to the object with the rigid body:

public void OnTriggerEnter(Collider c)
{
        Debug.Log("Collided!");
}

Now the scenario. The object that doesn't have the rigid body is actually a prefab, I am creating clones of it every few seconds and moving them across the screen. If they hit the other object (the one with the rigid body), I should get a "Collided!" message in the console. It works IF i move the rigid body object (with mouse input) AFTER the clone has spawned and they collide. However, if a clone spawns, moves across the screen and hits the rigid body object, and I have not moved the rigid body object (via mouse input), then there's no "Collided!" message, hence no collision. Any ideas why?

Note: When the collision works, the rigid body object is not moving at the time of collision. It has stopped moving by the time the clone hits it, and collision works. If I then leave the rigid body object in its place, and another clone spawns in the same place as the first clone, moves across the screen and hits the rigid body object, there is no collision.

Comment
Add comment · Show 3
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 Peter G · Dec 09, 2010 at 04:08 AM 0
Share

It also depends on how you move your objects. Try marking is$$anonymous$$inematic.

avatar image disband85 · Dec 09, 2010 at 05:04 AM 0
Share

marking 'is$$anonymous$$inematic' made it worse, it only collides now while the rigid body object is actually moving during the collision.

avatar image disband85 · Dec 09, 2010 at 05:04 AM 0
Share

I logged out the positions of both sprites. The positions are the same in both scenarios (when I move the rigid body object and when i don't move it). Yet, collision works when I move it, and doesn't work when I don't move it. It's as though when I move the object, something with it says 'ok i'm ready to run OnTriggerEnter when I collide with something'. Then as soon as it does collide with something, it never runs OnTriggerEvent anymore, until I move the object again. Like the trigger gets turned off when the trigger runs, then turns back on when I move the object.

1 Reply

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

Answer by disband85 · Dec 09, 2010 at 05:32 AM

Fixed the problem. I added a rigid body to the other object.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Weapon System with collide detection (Helps with script pls)!!! 0 Answers

Collision Enter one of the objects ? 1 Answer

How to make an object follow along the shape of another? 3 Answers

Fitting 2D collider to a sprite 0 Answers

Particle Collision / Trigger not being reported to On_xx Event 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