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 /
This question was closed Aug 31, 2015 at 09:16 PM by Ashky for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ashky · Aug 28, 2014 at 03:11 PM · 2dcolliderphysics2dkinematicempty game object

How to check for collision between a moving kinematic object and an empty object?

Hello, Unity Community!

I have an elevator (sprite) in my platformer, but I am having trouble making it stop.

I am moving it using this: rigidbody2D.MovePosition(rigidbody2D.position + Vector2.up* Time.deltaTime);, while a variable moving is true;

I have also created an empty game object and attached a collider to it. Now, I have this code here that should detect when my elevator collides with the empty game object, and then make the variable moving false.

 void OnCollisionEnter2D(Collision2D coll) {
      if (coll.gameObject.tag == "ElevatorStop")
         {
             moving=false;
         }
     }

Now, to clear some questions that might arise: the empty game object has the "ElevatorStop" tag, the layers on which both objects are found can interact, and both objects have "isKinematic=true".

What am I doing wrong? Or, how would this be achieved with an alternate solution? The solution should be general, because I plan on attaching this script to a prefab.

EDIT: After a bit of tweaking, I noticed that " if (coll.gameObject.tag == "ElevatorStop") " is never true. Ideas?

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

3 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Kiwasi · Aug 28, 2014 at 06:34 PM

Two kinematic colliders will never collide.

Setting isKinematic tells the engine "Don't worry about adding forces to this, I'm going to control it by script".

Two options to solve

  1. Set isKinematic to false on the elevator stop

  2. Change the collider on elevator stop to a trigger and use OnTriggerXXX

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 Ashky · Aug 28, 2014 at 07:03 PM 0
Share

Oh, hey, it's you! You've answered my question before. Anyways, thanks. I'm using OnTrigger now, works great.

avatar image
0

Answer by AngryBurritoCoder · Aug 28, 2014 at 03:16 PM

Why don't you just animate the elevator to go up? It's easy and simple for an upward or downward motion

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 Ashky · Aug 28, 2014 at 05:29 PM 0
Share

Could you elaborate, please?

avatar image
0

Answer by Doodlemeat · Aug 28, 2014 at 05:53 PM

You have to give your empty gameobject a collider. I would give it a boxcollider. You cant detect collision between an empty game object and an object with a collider attached to it.

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 Ashky · Aug 28, 2014 at 05:57 PM 0
Share

Sorry, I already specified this in my original question: "I have also created an empty game object and attached a collider to it."

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Ball bounces in the wrong direction 1 Answer

Colliders in a wall jut out 0 Answers

How can I see my physics2d joints? 0 Answers

Using child colliders with rigidbodies/joints in 2D 0 Answers

OnTriggerEnter and OnTriggerExit both trigger twice 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