Home Unity

parent / child unexpected rotation problem

mod
Offline / Send Message
rooster mod
heyo

this is the opposite of how these questions normally go. Usually someone has scale on the parent and is wondering why the child rotation is skewed, but this time I want that effect and it's not working the way I think it should in Unity.

Here's the setup: I have a wheel I want to skew at an angle the faster a vehicle is moving, something like this:

http://img0094.popscreencdn.com/123504426_hermans-hot-rod-koach-dragster-cartoon-t-shirt-9666-ebay.jpg

so, I have an empty gameobject in Unity which is scaled and rotated, and a wheel beneath it, with scale 1,1,1. in the editor, if I rotate the wheel in x it behaves as expected- it rotates but is skewed by its parents scale.

but if I make a script animate its X rotation, the scaled wheel rotates as if it has scale applied to itself rather than its parent.

here's a sample scene demonstrating what I mean- if you rotate the child in X, you'll see the desired effect:
https://dl.dropbox.com/u/8878789/wheelRotation.zip

can anyone think of a way to get this working in play mode though?

Replies

  • rooster
    Offline / Send Message
    rooster mod
    I've been chatting to someone on twitter about this and they suggested continuously setting the parent's scale to 'force the transform to update'.

    this has fixed it! I literally did this: transform.localScale = transform.localScale and the skew effect is up and running.

    this does lead me to the question: why is that necessary? is unity doing some kind of optimisation somewhere under the hood? what else don't I know about :S
  • commander_keen
    Offline / Send Message
    commander_keen polycounter lvl 18
    Yeah that sounds like its probably a bug in dynamic batching or something.
Sign In or Register to comment.