- Home /
Prefab changing dimensions when parent changed
First question at Unity Answers so hopefully I can be clear. Thanks for the all the great information here - fantastic community!
I am cloning a new instance of a prefab when the user right clicks their mouse. They can then move the mouse around and rotate the object on the X and Y axis. The problem is I parent the clone to the player transform and then unparent when the player lets go of the right mouse button. When that happens the dimensions of the model gets twisted based on what angle it's at when they let go. :/
So, a wood 'plank' prefab becomes a 2x4 at one angle and skis at another angle.
// Happens when you right click
function carryPlank()
{
var clone : GameObject;
var distance : float = 15;
var throwPos : Vector3 = transform.TransformPoint( Vector3.forward * distance );
clone = Instantiate ( plank, throwPos, transform.rotation );
clone.rigidbody.isKinematic = true;
clone.transform.parent = transform;
assetHeld = clone;
}
// Happens when you let go
function dropAsset()
{
assetHeld.transform.parent = null;
assetHeld.rigidbody.isKinematic = false;
}
Answer by DaveA · Aug 09, 2013 at 03:49 AM
Well that's odd, but a quick fix might be to set the localRotation to Quaternion.identity, and localScale to Vector3.one afater setting the parent to null
Your answer
Follow this Question
Related Questions
Instantiated object rotation abruptly. 0 Answers
How to make an Instantiated prefab a Child of a gameobject that already exists in the hierarchy 3 Answers
Physics related rotation problem. (a weird one) 0 Answers
Instantiated Object looses prefab's rotation 10 Answers
Problem setting the parent. 1 Answer