Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
5
Question by _MGB_ · Aug 20, 2012 at 10:10 AM · rotationtransformmeshbillboarding

Rotate only mesh (not whole GameObject)

Hi all, I'm trying to billboard the mesh on a GameObject without rotating the collider too. I've tried fiddling with: renderer.transform, MeshFilter.transform, MeshRenderer.transform... all of them seem to ref the main object transform. Any idea if this is possible?

Comment
Add comment · Show 2
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 Khada · Aug 20, 2012 at 05:05 PM 0
Share

Did that do the trick? Don't forget to mark the question as answered if it did.

avatar image AlucardJay · Aug 20, 2012 at 05:29 PM 0
Share

@$$anonymous$$GB this is an interesting but tricky question. The only way I see it to be possible is to re-position all the vertices in the mesh. Building an array of verts and assigning new positions for the verts would be the easy part, the tricky part would be calculating what rotation from the origin of the gameObject to apply to the verts (hence a comment, not an answer). I shall think about this and post an answer if I solve the vert relocation equation to billboard to the camera.

EDIT : I have just submitted an answer ($$anonymous$$ $$anonymous$$ay) =]

4 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Khada · Aug 20, 2012 at 10:53 AM

The transform on that object hold the transform data for all components attached to it. You'll need to create a new GameObject and keep your mesh/collider separate so that you can manipulate them independently.

EDIT: Or what deekr said, which effectively gives the mesh a new game object behind the scenes.

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 Bunny83 · Aug 20, 2012 at 07:39 PM 0
Share

But if it's not yet a Skinned$$anonymous$$eshRenderer it's way better to just have the mesh as child. The Skinned$$anonymous$$eshRenderer has some overhead since it has to "skin" the mesh each frame.

avatar image _MGB_ · Aug 21, 2012 at 09:05 AM 0
Share

@$$anonymous$$hada This seems to be the most intuitive solution (parenting another GameObj), cheers.

avatar image Khada · Aug 21, 2012 at 01:15 PM 0
Share

You're welcome :)

avatar image
5

Answer by AlucardJay · Aug 20, 2012 at 06:51 PM

After some very quick testing on a cube, I think I have the solution =]

Create a new scene, create a Cube and attach the below script. Hit play, change the value rotatedAngleY in the Inspector, then left-click in the game view. In the scene view, the collider should be visible as a wireframe, and this should be at the original rotation while the cube has rotated to the angle set by rotatedAngleY. How you calculate and implement rotatedAngleY is up to your scene. Hope this helps =]

 #pragma strict
 
 public var theObject : Transform;
 private var theMesh : Mesh;
 private var originalVerts : Vector3[];
 private var rotatedVerts : Vector3[];
 public var rotatedAngleY : float = 0.0;
 
 function Start() 
 {
     if (!theObject)
     {
         theObject = this.transform;
     }

     theMesh = theObject.GetComponent(MeshFilter).mesh as Mesh;
     
     originalVerts = new Vector3[ theMesh.vertices.length ];
     originalVerts = theMesh.vertices;
     
     rotatedVerts = new Vector3[ originalVerts.length ];
 }
 
 function Update() 
 {
     if (Input.GetMouseButtonUp(0))
     {
         RotateMesh();
     }
 }
 
 function RotateMesh() 
 {
     var qAngle : Quaternion = Quaternion.AngleAxis( rotatedAngleY, Vector3.up );

     for (var vert : int = 0; vert < originalVerts.length; vert ++)
     {
         rotatedVerts[vert] = qAngle * originalVerts[vert];
     }
     
     theMesh.vertices = rotatedVerts;
 }
Comment
Add comment · Show 7 · 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 Bunny83 · Aug 20, 2012 at 07:45 PM 0
Share

Yes, this does work of course, but i think it's a bit uneffective. At least create the quaternion outside of the for loop. You create a new one for each vertex, but the values are the same.

Btw, when you rotate around the local axis it's a bit easier to use

 Quaternion.Euler(0,rotatedAngleY,0);
avatar image AlucardJay · Aug 21, 2012 at 06:03 AM 0
Share

Thanks for picking that up, I have edited the answer. But am questioning if I should remove it (or convert to comment).?

I am very inexperienced and have my own trouble implementing rotations, a fellow user showed me AngleAxis here: http://answers.unity3d.com/questions/300162/method-to-rotate-a-vector3-around-a-vector3-by-spe.html , and looking back to that I can see where I replaced my transform.RotateAround with AngleAxis in the loop (as you correctly pointed out is inefficient).

If you have any suggestions on how to make this not uneffective (or elaborate) I would be very grateful. (personally I couldn't see why the object isn't bounded by and correctly aligned to the collider, but $$anonymous$$e is not to question the vision or idea !)

Perhaps I should again refrain from submitting answers for a while, until I get some more practice and experience in, am wary of this after the first errors on the UV coordinates of a native cube question.

avatar image _MGB_ · Aug 21, 2012 at 09:07 AM 0
Share

While this would work, its very processor intensive to do every update!

avatar image AlucardJay · Aug 21, 2012 at 09:14 AM 0
Share

no worries, thanks for the feedback (and putting up with my enthusiasm!). I should've thought of separate gameObjects for obj and collider, having done that myself for a high-poly mesh with a custom low-poly mesh collider =]

avatar image Bunny83 · Nov 28, 2012 at 12:12 AM 2
Share

@numberkruncher: Exactly the same way. Just multiply them with the quaternion

Show more comments
avatar image
1

Answer by Sindorej · Dec 14, 2013 at 03:32 PM

In my opinion the best way is to create a game object that is a child of the main object and add the mesh collider to the child.

Comment
Add comment · 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
0

Answer by deekr · Aug 20, 2012 at 11:54 AM

You could give the mesh a root bone in your modeling package and then transform it.

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 Owen-Reynolds · Aug 20, 2012 at 07:39 PM 0
Share

Or, in Unity, do the same thing by parenting an empty gameObject to the mesh.

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

14 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

Related Questions

How to rotate child 3D object to match bend of mesh 1 Answer

Change Pivot Point- Maya 3 Answers

rotation script in unity 3 Answers

[Help] Object flips around when using transform.Rotate 3 Answers

Trying to rotate weapon 0 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