• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

AddForce to parent based on child's rotation C# 1 Answer

How do I call a function containing a while loop, inside the update function? 2 Answers

Rotation problems when I child a sword to players hand! (pictures within to clarify) 1 Answer

Flip over an object (smooth transition) 3 Answers

Rotation no save to array 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges