Search code examples
unity-game-engineunityscriptgameobject

Scaling a wheeled car GameObject in Unity3d with Wheels as Configurable Joint


In my application I want to resize my Car during Runtime. I used the following command to do that.

myCar.transform.localScale = new Vector(x,y,z);

before executing the above command I am enabling isKinematic property in rigid bodies which are childs of myCar. My hyrarchy is as follows.

myCar is Parent GameObject. Its children are Base, Left_Wheel and Right_Wheel.

In this one, Base, Left_Wheel, Right_Wheel are rigid Bodies, but myCar Gameobject is not a rigid body. So I am enabling the isKinematic propertly of all these 3 before resizing the myCar Object.

base.rigidbody.isKinematic = true;
leftwheel.rigidbody.isKinematic = true;
leftWheel.rigidbody.isKinematic = true;

after doing so, I am increasing the localScale of myCar GameObject and entire entity is rescaling as expected, but after that when I disable the isKinematic property in rigidbodies my both wheels went to the default position, or in other words they went inside the car.

I am doing all the above operations in FixUpdate, but I don't understand where I am doing wrong.

Any help will be appreciated. Remember in the above hierarchy myCar gameObject is not rigidbody only its children are rigidbodies.

Thanks.


Solution

  • Probably joints' anchors weren't updated properly. Though Unity v4.3.4f is able to update joints according to object scale I cannot guarantee the earlier versions are able to do so.