unity3d - How to rotate object around self center without any misshape? -


after adding instantiated prefab parent want rotate new prefab around self center.

gameobject clone = instantiate(mockup, transform.position, transform.rotation) gameobject;  clone.transform.parent = gameobject.transform; clone.transform.localposition = vector3.zero; clone.transform.rotate (0, 45, 0); 

but misshape prefab. in case when not set parent rotates without misshaping. tried rotatearound , pass clone.transform.localeposition parameter still same. tried center

clone.getcomponent<renderer>().bounds.size; 

and add position , pass parameter still no success.

how rotate object around self center without misshape ?

misshape: camera above , scale , rotate cube above not rectangle should be

enter image description here

without rotation:

enter image description here

after experiment able replicate probem. problem on line of code gameobject clone = instantiate(mockup, transform.position, transform.rotation) gameobject;

you passing transform.rotation new position of new instantiated gameobject. transform.rotation rotation of gameobject script attached to. x or z axis of gameobject script attached 0. mine 25 , yours should similar.

several ways fix it:

1.simply make sure x,y or z axis of gameobject script attached set 0. if don't want change 1 of other solutions below.

enter image description here

2.another way of solving not proving position or rotation during instantiate since override both position , rotation clone.transform.localposition = vector3.zero; , clone.transform.rotate (0, 45, 0); later on. so, current code redundant.

gameobject clone = instantiate(mockup) gameobject; 

3.finally, way solve provide 0 rotation quaternion.euler(vector3.zero) third parameter instead of transform.rotation.

gameobject clone = instantiate(mockup, transform.position, quaternion.euler(vector3.zero)) gameobject; 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -