cancel
Showing results for 
Search instead for 
Did you mean: 

Physics grabbable wrong calculate (Solved) mb some have this problem

FHN
Honored Guest

The problem at hand is that when I grab an object and try to throw it, it behaves unpredictably, sometimes stopping abruptly and other times flying in the opposite direction.

Upon investigation of how it works, the following chain of events can be observed: There is a GrabInteractor that interacts with the GrabInteractable (which can be HandGrabInteractable/ControllerGrab, etc.). Then, the Interactable checks for the presence of a PhysicsGrabbable (a component that applies force upon release). Additionally, there is a VelocityCalculator that calculates the force to be applied.

If the VelocityCalculator is absent, the object will enable its physical properties but will stop since the Velocity is set to 0.

Alright, so we've figured that out. However, the connected calculator is acting strangely and launching in random directions. The issue lies in the linkage. The Interactor passes information about the HandGrabInteractable along the chain instead of the object itself, which may be located at different points. This is because it also handles the visual positioning of the hand (as shown in the photo). But we need it to calculate the object. Fortunately, most of the necessary fields are accessible, and we can refer to the Rigidbody of the interacting object, thereby adding the Rigidbody property to the HandGrabInteractor script:

 

 

protected override void InteractableUnselected(HandGrabInteractable interactable)
{
    base.InteractableUnselected(interactable);
    this.Movement = null;
 
    ReleaseVelocityInformation throwVelocity = VelocityCalculator != null ?
        VelocityCalculator.CalculateThrowVelocity(interactable.Rigidbody.transform) :
        new ReleaseVelocityInformation(Vector3.zero, Vector3.zero, Vector3.zero);
    interactable.ApplyVelocities(throwVelocity.LinearVelocity, throwVelocity.AngularVelocity);
}

 

I have highlighted the added section in the script.

 

photo_2023-07-04_13-41-12.jpg

1 REPLY 1