Hi all I have a problem with making correct movement in my 2D environment:
I have a script on parent object that basically does this:
void Update () {
if (child.GetComponent<Rigidbody2D>().angularVelocity == 0 ) {
child.GetComponent<Rigidbody2D>().angularVelocity = 20;
}
}
It gives the child angular velocity, that is fine and dandy
Also i have another script attached to the parent object that pushed the object in a linear way like this:
void Update () {
if (activated && totalPush < 20) {
gameObject.GetComponent<Rigidbody2D>().MovePosition(new Vector2(transform.position.x +2, transform.position.y));
totalPush += 2;
} else {
activated = false;
}
}
I simplified both codes for easy understanding. My problem is that the child is rotating in a constant rotation when staying still, but when the parent starts to move (and of course child object moves with it) the child stops rotating, until parent stops, and then starts to rotate again. printing out child angular velocity to the console in update, gives a constant ‘20’, even the brief moment it is not rotating (the rotation value in transform in the editor is not changing however, hence the absence of rotation)
Any ideas?
EDIT: I’m using Unity 5.4.0b13
EDIT 2: If I’m making the rotation script turn the parent object, then it working correctly (its moves and rotates at the same time)