x35mm

Hi guys,

Pretty sure I'm missing something obvious here, but can't spot what the issue is.

I have a skeleton and I'm spawning bullets from a child bone using the following code:
var bullet = Instantiate(_bulletPrefab, _turretEmitPoints[turretIndex].position, _turretRotateTransforms[turretIndex].rotation);
bullet.RunOnChildrenRecursive((g) => g.layer = _projectileLayer);

var rigidBody = bullet.GetComponent<Rigidbody2D>();
rigidBody.velocity = rigidBody.transform.right * 5f;
This works fine when the root bone scale is 1, 1, 1 but when I change the root bone scale to 1, 0.7, 1 the rotation is then off. I've tried using WorldRotationX on the bone object itself, but it always seems to ignore the effect scaling in Y has on the world rotation.

Is there another property or some transform I need to apply to get the accurate rotation?

Here the root bone is 1, 1, 1 scale
Capture.PNG


Here is when the root bone is 1, 0.7, 1 scale
Capture1.PNG
У вас нет необходимых прав для просмотра вложений в этом сообщении.
Аватара пользователя
x35mm
  • Сообщения: 43

Harald

In general, combining non-uniform scaling (not scaling x,y,z coords by the same value) at a parent object and rotation by other angles than 90,180,270 degrees at a child object can yield unintuitive effects in 2D and 3D graphics.

In your case you have actually discovered a limitation of the SkeletonUtilityBone compared to the BoneFollower, at least I guess you are using the SkeletonUtilityBone hierarchy for the _turretRotateTransforms[turretIndex]. SkeletonUtilityBone assigns the undistorted angles to the Transforms, whereas BoneFollower respects non-uniform scale.

So in short, you could have a try with using a BoneFollower component instead to follow the rotation of your turret.
Please let me know if my guess was wrong and your setup is different.
Аватара пользователя
Harald

Harri
  • Сообщения: 1054

x35mm

Perfect!! You were spot on about my setup, and switching to BoneFollower is now respecting the non-uniform scale.

Thank you!
Аватара пользователя
x35mm
  • Сообщения: 43

Harald

Great to hear, glad it worked! Thanks for letting us know.
Аватара пользователя
Harald

Harri
  • Сообщения: 1054


Вернуться в Unity