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
1
Question by pma07pg · Jan 11, 2012 at 05:38 PM · transformtriggerparenting

Parenting trigger moving platform

I want to have a player move with a platform whenever the player is on it. I have this script which works when the player jumps on the platform but not when he leaves.

My script is below. I don't know why is isn't working as it works with booleans but just not transforms!

 var platform : Transform;
 var player : Transform;
 
 
 function OnTriggerEnter()
 {
     if(player.tag == "Player1")
     {
             
         player.transform.parent = platform.transform;    
     }
 }
 
 function OnTriggerExit()
 {
     if(player.tag == "Player1")
     {
         player.transform.parent = null;                
     }
 }

I want to increase this to four players but it doesn't even work for one... Any help would be great.

Cheers, Peter

Comment
Add comment · Show 2
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 Berenger · Jan 12, 2012 at 05:46 AM 0
Share

Is that script attached to the platform or the player ? Either you don't need to declare two transforms.

avatar image pma07pg · Jan 12, 2012 at 10:10 AM 0
Share

The script is attached to the trigger which is parented to the platform. Sorry, I don't fully understand your comment!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Jan 12, 2012 at 11:01 AM

You should change this script a little, and attach it to the trigger object; the trigger object, in turn, must be childed to the platform.

function OnTriggerEnter(col: Collider) { if(col.tag == "Player") { col.transform.parent = transform.parent; } }

function OnTriggerExit(col: Collider) { if(col.tag == "Player") { col.transform.parent = null; } } When any character tagged "Player" enters the trigger volume, this script childs the character to the platform (the trigger's parent). When the character exits the trigger, the parenthood is broken. This will work for any number of players, provided that all of them have the same tag "Player".

Comment
Add comment · Show 7 · 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 pma07pg · Jan 13, 2012 at 10:30 AM 0
Share

Hey Aldonaletto. Thanks for replying. The OnTriggerEnter function works perfectly. However, the OnTriggerExit doesn't work and after leaving the volume the player continues to move! Do you know why this would happen?

avatar image Kaze_Senshi · Apr 01, 2012 at 03:42 PM 0
Share

Try to remove some rigidBody component in your moving platform if it has someone, it seems like a Unity bug that the OnTriggerExit does not work if you put a rigidBody component on it. I have this issue too and did it to solve.

avatar image munaeem · Nov 11, 2012 at 01:24 PM 0
Share

i have an issue Aldo please help. $$anonymous$$y player is slimmed out/ Squashed/ thin. $$anonymous$$y player is changing scale but i have used this script to resize but does not work. Tried everything.

transform.localScale = Vector3(1,1,1);

This makes it very complicated and mess up my character

avatar image aldonaletto · Nov 12, 2012 at 03:13 AM 2
Share

If you child the player to a non-uniform scaled object (different scales for x, y and/or z), it gets distorted. The solution is to make the platform an empty object with scale (1,1,1) and child the platform model and the trigger to it. The platform hierarchy should be something like this:

 Platform  <- empty object
   $$anonymous$$odel <- cube scaled to the desired dimensions
   Trigger <- box collider with the desired dimensions

The trigger script should be attached to the Trigger object, and refer to its parent, the Platform object (like in the answer above):

 function OnTriggerEnter(col: Collider){
   if (col.tag == "Player"){
     // child the player to the trigger parent:
     col.transform.parent = transform.parent; 
   }
 }

 function OnTriggerExit(col: Collider){
   if (col.tag == "Player"){
     // unchild the player from the platform
     col.transform.parent = null; 
   }
 }
avatar image munaeem · Nov 12, 2012 at 07:41 PM 0
Share

Thank you sooo sooo much man #Respect you. Actually this is my first question that i understood with your answer. \really happy about it thank you :)

Show more comments

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Acces to other object trigger thru other object script 0 Answers

Get the colliders transform (?) 1 Answer

A transform.position to act as a Vector3 1 Answer

Instansiate object into hand with a trigger, help... 0 Answers

Changing the parent transform of the First Person Controller 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