Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by chetan_dabhi · Apr 16, 2016 at 09:42 AM · colliderobjecty axis

How to collide obstacles each other like flappy crush game in unity?

i try to collide obstacle each other each other on y axis like flappy crush game so any how can do?this is reference link:https://www.youtube.com/watch?v=4JLjOO6tlDE

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 Blue-Cut · Apr 16, 2016 at 09:55 AM

------------- About collision ----------------

Check the documentation : http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter2D.html

Your 2D birds and obstacle need to have a 2D collider on their sprite. Put on these elements a custom script that implements OnTriggerEnter2D . This method will be called when an other collider enter in their area.

You could for example put it on the obstacle and do something like this :

  // We are in the script of the obstacle
  void OnTriggerEnter2D(Collider2D other) 
 `{
      // "other" is the bird that collides with it , you kill him
      Destroy(other.gameObject);
  }

------------- About moving obstacles ----------------

You have 1 pipe up and 1 pipe down. And at each frame, you make them move until they collide.

 // Set this to 1 or -1 to make your pipe move up or down
 public int direction;
 
 // The speed of the pipe
 public float speed;
 
 void Update()
 {
   // use the Translate method to move a transform
   transform.Translate(0f, speed*direction*Time.deltaTime, 0f);
 }
 
 // Then check the collision between the obstacles
   void OnTriggerEnter2D(Collider2D other) 
  `{
      // Let's assume that you identify your pipe with a tag
       if(other.tag == "Pipe")
       {
            // Inverse the direction so the pipes get back to their positions
             direction *= -1;
       }
   }

Complete this with something similar to inverse the position again when the pipes are back to their initial positions. Notice that your 2 pipes always have an opposed direction at the same time.

I wrote this in blind but this is the idea.

Comment
Add comment · Show 6 · 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 chetan_dabhi · Apr 16, 2016 at 10:10 AM 0
Share

I only collide obstacle each other.

avatar image Blue-Cut chetan_dabhi · Apr 16, 2016 at 10:17 AM 0
Share

I guess that is where your problem starts. The birds are involved here.

What you need to do is setting some boolean true when the obstacles collide and false when they stop colliding.

Then next to this, you check if your bird collide with an obstacle. If it collides with an obstacle AND your boolean is true because the obstacles are colliding, then your bird is killed.

avatar image chetan_dabhi · Apr 16, 2016 at 10:31 AM 0
Share

I don't crush bird actually what i need i explain: in my game two obstacles (pipe)on y axis now obstacles are fix position buy now i want to this two obstacles collide with each other on y axis.

avatar image Blue-Cut chetan_dabhi · Apr 16, 2016 at 10:59 AM 0
Share

Edit, is this what you were thinking about ?

avatar image chetan_dabhi · Apr 16, 2016 at 11:22 AM 0
Share

ok ,thanks i try it .

avatar image Blue-Cut chetan_dabhi · Apr 16, 2016 at 11:30 AM 0
Share

What I am giving you here is a kind of guideline, copying this code won't be enough if you want that all work as you want. But it's definitly a good base to start.

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

63 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 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 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

Why isn't my object destroying on collision? 1 Answer

Moving instantiated Objects to target locations 1 Answer

2d box collider not working (have rigid body) 0 Answers

Rotating Gameobject not Colliding 1 Answer

Object passes through other moving objects 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