How to prevent picked up object from changing its scale?

Viewed 67

I'm facing an issue when I pick up an object in my game. Whenever I pick up an object and look around while holding the object, it stretches based on the perspective. Here is an example of an object before and after picking up:

Before picking up:

Here is the original item size

After picking up: Here is how it becomes after

How can I maintain the object's scale and prevent it from stretching?

    public void PickupObject()
    {
    physicsObject = lookObject.GetComponentInChildren<PhysicsObjects>();
    currentlyPickedUpObject = lookObject;
    pickupRB = currentlyPickedUpObject.GetComponent<Rigidbody>();
   /* priorConstraints = pickupRB.constraints;    // <--- NEW
    pickupRB.constraints = RigidbodyConstraints.FreezeAll;    // <--- NEW*/
    pickupRB.constraints = RigidbodyConstraints.FreezeRotation;
    physicsObject.playerInteractions = this;
     pickupRB.isKinematic = true;
     pickupRB.transform.parent = PickupParent.transform;
    //   pickupRB.isKinematic = true;
    //  StartCoroutine(physicsObject.PickUp());
}

The following code snippet is in Update() :

if (currentlyPickedUpObject != null)
        {
            
            HoldingItemIcon.SetActive(true);
            InteractIcon.SetActive(false);
            CenterIcon.SetActive(false); 
            currentDist = Vector3.Distance(PickupParent.position, pickupRB.position);
            currentSpeed = Mathf.SmoothStep(minSpeed, maxSpeed, currentDist / maxDistance);
            currentSpeed *= Time.fixedDeltaTime;
            pickupRB.transform.position = PickupParent.position;
            // pickupRB.transform.SetParent(PickupParent.transform);
            Vector3 direction = PickupParent.position - pickupRB.position;
            pickupRB.velocity = direction.normalized * currentSpeed;
            Vector3 camerDirection = mainCamera.transform.forward;
            // Throw object
            if (Throw)
            {
                HoldingItemIcon.SetActive(false);
                InteractIcon.SetActive(false);
                pickupRB.constraints = RigidbodyConstraints.None;
                pickupRB.isKinematic = false;
                pickupRB.AddForce(camerDirection * 500);
                currentlyPickedUpObject = null;
                pickupRB.transform.parent = null;               
            }
            Throw = false;

        }

 public void BreakConnection()
        {
          pickupRB.isKinematic = false; 
          pickupRB.transform.parent = null;
          pickupRB.constraints = priorConstraints;
          //   pickupRB.constraints = RigidbodyConstraints.None;
          currentlyPickedUpObject = null;
          lookObject = null;
          physicsObject.pickedUp = false;
          currentDist = 0;
          pickupRB.useGravity = true;
    }

enter image description here

enter image description here

pickupParent's lossy scale while an object is picked:

enter image description here

1 Answers

What you can do is have an empty gameObject as a child of your player. That object is going to be the pickableObjectsParent and give this parent object the scale values of 1/(player's scale).

Related