scaling up a rigidbody object in 2d

I use DoTween for tweening, and I’ve always used transform.DOScale, but for rigidbody objects should you be tweenining the transform through the rigidbody for more precise collisions? If you get the transform from the rigidbody component via GetComponent.transform, is the rigidbody controlling the transform or are you just getting the transform from the gameobject the rigidbody component is attached to?

.transform always gives you the transform component of the game object. That even works if your component is your own script without you having had to define “transform” because it’s provided through the MonoBehavior inehritance.
→ There is only one transform per game object and it doesn’t make a difference how you access it (except a performance difference in your case because GetComponent() is relatively slow. Don’t do that constantly in an update method but cache the component).

That said, whenever possible try to avoid manipulating the transform of an object that has a rigidbody as well as colliders. Rigidbodies expect to run into collisions “on their own”, aka from their velocity or rotation. If you set the scale or the position by code, you can bring the object into a state it could never reach “on its own” and that usually results in erratic movement and the collisions not resolved as expected (-> clipping through terrain etc.).

Am assuming you are doing something like having an object expand and push everything of the way, right?
Since there is no growth directly for rigidbodies, sadly that’s a weakness of Unity’s 2D system. Probably wont be absolutely perfect the trivial way. If you really need that, consider spawning invisible extra rigid bodies which are using velocity to push along the edges of your main object.

1 Like