Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Ammo no Longer Follows Weapon after Upgrading from 2021 to 2022

Discussion in 'Editor & General Support' started by Davex6, Jun 14, 2023.

  1. Davex6

    Davex6

    Joined:
    Mar 29, 2023
    Posts:
    49
    First off, this is an Android project; however, the problem occurs both on physical devices and the editor-simulator.
    Basically, the weapon (a slingshot) is grabbed by the shaft so it can be moved along the x-axis. The ammo (sphere) is placed in between the slingshot prongs by:
          NFAmmoGO.transform.position = ammoWP;

    In v2022, the weapon can be moved slowly along the axis and the ammo keeps up. Rapidly moving the weapon causes the problem, at its worst, the ammo stays at the opposite side of the screen to the weapon.
    VS debugging shows that the NFAmmoGO.transform.position is being updated correctly, but this movement is not updated in the scene. I've taken all other objects out of the project, except weapon/ammo and it is reproducible just by updating from v2021 to 2022.

    Thing is, I'm relatively new to Unity and cannot be 100% sure it is not something else in my code causing this, nevertheless, it works perfectly in 2021. Maybe I should file a Bug Report?

    Code (CSharp):
    1.         public void MoveWeaponXAxis(Vector3 mouseWPos)
    2.         {
    3.             mouseWPos.y = gameObject.transform.position.y;
    4.             gameObject.transform.Translate(mouseWPos - gameObject.transform.position, Space.World);
    5.             Vector3 ammoWP = NFAmmoGO.transform.position;    
    6.             ammoWP.x = GetStartPos().x;
    7.             NFAmmoGO.transform.position = ammoWP;
    8.         }