Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 MidnightDragonT · Jan 16, 2016 at 08:54 AM · collisionplayerpositioningfollowingxyz

If collided have ObjectA follow ontop of ObjectB

I'm trying to make it where when a player collides with a bubble it will stay on the object it collided with, the catch is that there are multiple objects that the player play as, here's part of the code I've been messing around with for the past couple of days. It will only jump to 27 units on the x-axis from the original position.

Because once the timer runs out the bubble pops and returns to home location. (Which does work currently)

 void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.tag == "Player") {
             attached = true;
             
             transform.position.x = other.transform.position.x;
             transform.position.y = other.transform.position.y; 
             transform.position.z = other.transform.position.z; 
         }
     }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by vintar · Jan 16, 2016 at 12:27 PM

You could just set the player as a child of the bubble it collides with, and unchild it when the bubble pops. Like :

 void OnTriggerEnter(Collider other)
 {
          if (other.gameObject.tag == "Player") 
        {
              attached = true;
              
              transform.SetParent(other.transform);
         }
  }

then when the bubble pops :

 transform.parent = null;

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 MidnightDragonT · Jan 18, 2016 at 10:46 PM 0
Share

If I pause the game and zero out the position it will go to where it needs to be. How would I make the code itself do that? @vintar

avatar image MidnightDragonT · Jan 19, 2016 at 09:09 AM 0
Share

I added this to make it stay on the player after the testing if the other object is the player.

                  transform.localPosition = new Vector3(0, 0, 0);
avatar image
0

Answer by MidnightDragonT · Jan 17, 2016 at 10:51 AM

Sadly that didn't help it makes the bubble go off screen, I believe on the z axis.

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

44 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

Related Questions

Automatically flip a player game object upright on z axis? 1 Answer

Making a Game Save hitting a trigger 1 Answer

Special collision for players 1 Answer

How to detect player collision in an object 0 Answers

how to add rigidbody to my mouseposition 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