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
0
Question by MK7 · Apr 17, 2011 at 04:52 AM · rotationfunctionparentingunparentingcustom-function

Creating a function that parents player to object and then unparents it

I have a game where the player can rotate a level around them by pressing a button. but when I rotate the level a certain way the level heavily pushes the player; so much so that at times the player gets flung so fast it ignores any colliders I set up. I'm under the impression that parenting the object to the level while it's rotating and then un-parenting upon completion should solve this problem; but I haven't a clue how to go about doing that without using triggers. Could somebody help?

Added code I have so far


function RotateObjectForward(point : Vector3, axis : Vector3,rotateAmount : float, rotateTime : float) { var rotation = Quaternion.AngleAxis(rotateAmount, axis); var startPos : Vector3 = transform.position - point; var endPos : Vector3 = rotation * startPos; var startRot : Quaternion = transform.rotation; var step : float = 0.0; //non-smoothed var smoothStep : float = 0.0; //smoothed var rate : float = 1.0/rotateTime; //amount to increase non-smooth step by Player.transform.parent = Parent.transform; while(step < 1.0) { // until we're done step += Time.deltaTime * rate; //increase the step smoothStep = Mathf.SmoothStep(0.0, 1.0, step); transform.position = point + Vector3.Slerp(startPos, endPos, smoothStep); transform.rotation = startRot * Quaternion.Slerp(Quaternion.identity, rotation, smoothStep); yield; } //finish any left-over if(step > 1.0) { transform.position = point + endPos; transform.rotation = startRot * rotation; } Player.transform.parent = null;

}


I get this weird error that says "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption."

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
1
Best Answer

Answer by Eric5h5 · Apr 18, 2011 at 02:20 AM

Set the transform of the instance of the prefab, instead of the actual prefab.

Comment
Add comment · Show 3 · 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 MK7 · Apr 18, 2011 at 04:35 PM 0
Share

I'm sorry I'm not quite sure I understand...

avatar image Eric5h5 · Apr 18, 2011 at 08:48 PM 0
Share

Use the instance of the prefab that's instantiated into the scene. Not the actual prefab.

avatar image MK7 · Apr 19, 2011 at 01:03 AM 0
Share

I think I got it work, but I guess it wasn't what I was lookin for. At least I understand how to do it now, Thanks a bunch!

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

No one has followed this question yet.

Related Questions

How can I stop a parented object from resetting its transform when a parent animation play? 1 Answer

Children ignoring Parent control. [Solved] 1 Answer

Trying to understand parenting 1 Answer

X-Flip is making my rotation break? 2 Answers

how to make an objects rotation independent from its parents. 2 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