2D Toolkit Forum

2D Toolkit => Support => Topic started by: camel on August 06, 2013, 09:58:46 am

Title: Scaling sprites with rigid body problem
Post by: camel on August 06, 2013, 09:58:46 am
Hi,
I have an gameobject. That has child tk2d Sprite, with Rigidbody component attached. It's an simple cube.

I have made an prefab from this. That I'm instantiating at runtime. This is all working like expected.
But if I'm trying to change scale of sprite. Than this cube is correctly colliding with other objects. But it's not colliding with other cubes of same type.

If I doesn't change scale all is working again. If I change scale of tk2d sprite through inspector it works nicely.

Thanks
Peter
Title: Re: Scaling sprites with rigid body problem
Post by: unikronsoftware on August 06, 2013, 10:06:33 am
You shouldn't change the scale of rigidbodies / colliders at runtime. It tends to cause serious amounts of grief to the physics engine.

The tk2d inspector does things for "Edit mode", and that code isn't meant to run at runtime - its fine rescaling things when the physics engine isn't running. You can change transform.localScale, but you shouldn't.
Title: Re: Scaling sprites with rigid body problem
Post by: camel on August 06, 2013, 10:10:10 am
So if I want to create dynamic shapes at runtime. For example rods like in game fantastic contraptios. (simple creating cubes with size of mouse drag)
What's an correct way of creating them.

Just creating gameobjects tk2d sprites rigid bodies through script?
Thanks
Title: Re: Scaling sprites with rigid body problem
Post by: unikronsoftware on August 06, 2013, 10:49:16 am
A sure fire way to get this to work is to destroy and recreate the collider - you could try other things (disable, resize and re-enable) to get it to register properly.

As far as i remember, changing the scale in the inspector destroys and recreates the collider.