Hi everyone,
I’m working on a game similar to Settlers 2 / 3, but with free 3D graphics and more physics realism. Currently, I’m trying to get the forester and lumberjack done. The forester plants trees, which grow, and get chopped when fully grown by the lumberjack for wood.
My question is about growing trees. For simplicity, a “tree” is currently represented by a simple cylinder, which can grow in size and change color. Each tree has a rigidbody to enable physical interaction. For example, when chopped down, a falling tree may carry down other trees in the process.
I’m experiencing big problems with those bodies when their scale is increased to make them grow. They start moving on their own, pop out of the ground (even when placed directly above it), break hinges which should hold them in place and so on.
I think the problem is that I’m constantly modifying a rigidbody using scale and position to make it grow and stay in place. I know that rigidbodies should be treated with forces only to avoid weird effects.
I’ve searched for solutions for days, but didn’t find any. I thought about not modifying the rigidbodies at all but adding more and more to simulate growth, but this approach has problems, too.
Is there any way to grow a rigidbody in size which is resting on a surface in place?
These are the two lines of code which I currently use to make the “trees” (primitive cylinders) grow:
transform.localScale *= GrowthSpeed;
transform.position = new Vector3 (transform.position.x, transform.localScale.y, transform.position.z);