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 Vekoro · Mar 04, 2017 at 10:36 AM · playerplatformrotating

How can i rotate a 3D platform and fix a little problem?...

I am using the First Person Controller script from Unity. If i jump on a platform i use this script to hold the character on a platform, so he is moving with it:

     void OnTriggerEnter (Collider other)
     {
         if (other.gameObject.tag == "Player") 
         {
             other.transform.parent = gameObject.transform;
         }
     }
 
     void OnTriggerExit (Collider other) 
     {
         if (other.gameObject.tag == "Player") 
         {
             other.transform.parent = null;
         }
     }

The problem with that is... i also get the same rotation of that object(platform) and this makes the problem. If i jump on it or from it away. I get a whole different rotation on my character and it makes it unplayable.

To rotate the platform i use this script, both scripts are on the rotating platform:

     float y;
     public float speedY;
     void FixedUpdate ()
     {
         y += Time.deltaTime * speedY;
         transform.rotation = Quaternion.Euler(0,y,0);
     }
Comment
Add comment · Show 4
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 hexagonius · Mar 04, 2017 at 11:21 AM 0
Share

Of course the player is rotating with the platform. It depends on what you want to achieve. Try to explain what should happen when the player is on a platform and what happens when gets off it?

avatar image Vekoro hexagonius · Mar 04, 2017 at 11:30 AM 0
Share

I want if the player jumps on the platform, he stays with his own rotation he entered first (not changing to a complete new direction of rotation of that parent object), but if he stay on the rotating platform, he should then rotate from his local rotation with the platform together. If i jump off that platform, i want to stick with the new rotation the player had from that platform, so there are no fast camera rotation changes.

At the moment, if i jump on the platform, the player rotation change completely and if i jump off the platform, it also change again in his old local rotation (the same rotation he entered the platform first).

avatar image hexagonius Vekoro · Mar 04, 2017 at 11:40 AM 0
Share

The code in OnTriggerEnter should do what you wanted then.
For OnTriggerExit to work you'd need to save the players rotation in OnTriggerEnter and reset it after you've set the parent to null.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AMU4u · Mar 04, 2017 at 07:24 PM

     public bool onObject;
     public bool freeFromObject;
     
     void OnTriggerEnter()
     {
     freeFromObject = false;
     onObject = true;
     }
     
     void OntriggerExit()
     {
     onObject = false;
     freeFromObject = true;
     void IfFreeOfObjects()
     {
     Transform.Rotate(5*speed*Time.DeltaTime,0,0);
     }
     
     void IfOnObject()
     {
     Transform.Rotate(objectIWantToRotateWith);
     }
     
     
     Void FixedUpdate()
     {
     if(onObject)
     {
     IfOnObject();
     }
     else if(freeFromObject)
     {
     IfFreeFromObject();
     }
     }
 
 
 
 


Comment
Add comment · Show 5 · 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 Vekoro · Mar 04, 2017 at 08:39 PM 0
Share

@letitslide I tried your script to add it on the rotating platform, but it doesnt work. $$anonymous$$aybe there is something missing in that script?

avatar image AMU4u Vekoro · Mar 04, 2017 at 08:42 PM 0
Share

Well, it's psuedo-code that closely resembles real code. It's lacking a starting bracket on the class, the using UnityEngine and such at the start of the class. Just paste the values into a script that you are using that works, and resolve the syntax errors from there.

avatar image Vekoro AMU4u · Mar 04, 2017 at 08:48 PM 0
Share

error CS0120: An object reference is required to access non-static member `UnityEngine.Transform.Rotate(float, float, float)'

If i add the platform object and put it there, i get this message?

 void IfOnObject()
 {
     Transform.Rotate(platformObj);
 }
Show more comments
avatar image
0

Answer by reigota · Mar 13, 2017 at 01:54 AM

As @hexagonius said, use OntriggerEnter to store original player rotation and OnTriggerExit to restore it. But, to set the parente, use method .SetParent of the transform. It has a second parameter that lets you to keep original world position/rotation/scale while parenting..

Something like:

 Quaternion _playerOriginalRotation;
 
 void OnTriggerEnter (Collider other)
      {
          if (other.gameObject.tag == "Player") 
          {
              _playerOriginalRotation = other.transform.rotation;
              other.transform.SetParent( gameObject.transform, true);
          }
      }
  
      void OnTriggerExit (Collider other) 
      {
          if (other.gameObject.tag == "Player") 
          {
              other.transform.parent = null;
              other.transform.rotation = _playerOriginalRotation;
          }
      }
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 Vekoro · Mar 13, 2017 at 06:38 PM 0
Share

Hi @reigota thank you for helping, i tried this script of you, but i still got the same problem. I added it to the rotating platform, then the player with first person controller script (from Unity), is jumping on it and then i got the same rotation from that rotating object and the camera change each time i jump on it. The rotating platform problem seems to be not easy to solve. 109 peoples follow this question too. You have any idea why it still doesnt work?

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

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

Player Can Not get off platform 1 Answer

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

weird player movement when parented to moving platform 1 Answer

Why do tests run from the command line in player claim they aren't on the same platform as when run from player in editor? 2 Answers

Why is my Player game object not rotating with mouse movement in 'Survival Shooter' unity project 10 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