Hello Guest

Author Topic: Scaling sprites with rigid body problem  (Read 3978 times)

camel

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Scaling sprites with rigid body problem
« 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

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Scaling sprites with rigid body problem
« Reply #1 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.

camel

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Scaling sprites with rigid body problem
« Reply #2 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

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Scaling sprites with rigid body problem
« Reply #3 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.