0 votes
asked in InteractionSystem by (160 points)
edited by

Hey!

I'm trying to have a character pick up a framed picture from the ground, and look at it regardless of which direction they are coming from.

I have figured out how to pick up an object and create an offset hold position (via the youtube tutorial Interaction System part 2). However, when I pick up the picture frame, it is on a weird angle by default. So I need to introduce some kind of rotation offset also. My current attempt looks like this. I am fixing the rotation of the frame by adjusting the right hand effector rotation:

IEnumerator OnPickup()

    {

        ik = frame.lastUsedInteractionSystem.GetComponent<FullBodyBipedIK>();

        poser = ik.gameObject.GetComponentsInChildren<HandPoser>()[1];

        while (holdWeight < 1f)

        {

            ik.solver.rightHandEffector.rotation = Quaternion.Euler(handRotation);

            ik.solver.rightHandEffector.rotationWeight = .8f;

            holdWeight += Time.deltaTime;

            yield return null;

        }

    }

    void LateUpdate()

    {

        if (ik == null) return;

        holdPose.Apply(ik.solver, holdWeight, ik.transform.rotation);

    }

    private void Update()

    {

        if (ik == null) return;

        if (Input.GetKeyDown(KeyCode.D)) StartCoroutine(Drop());

    }

    IEnumerator Drop()

    {

        GetComponent<Rigidbody>().isKinematic = false;

        transform.parent = null;

        poser.poseRoot = null;

        poser.weight = 0;

        while (holdWeight > 0f)

        {

            holdWeight -= Time.deltaTime * 3f;

            ik.solver.rightHandEffector.rotationWeight = 0f;

            yield return null;

        }

    }

The problem with this solution; is that it breaks when used with the 'Fix Y-axis' feature on the interaction trigger - if you rotate around the frame, the wrist goes crazy! It also seems very buggy, and will cause strange wrist movements unless you pick up the object from exactly in front of it.

Why is this happening? Can anyone explain to me how to fix this problem?

Thankyou!
 

1 Answer

+1 vote
answered by (8.5k points)
selected by
 
Best answer
Hey,

It should be done by parenting the InteractionTarget to a pivot gameobject that is at the center of the frame. Then you can rotate that pivot when the interaction starts so that the target would be conveniently oriented relative to the direction from the character's current position to the object. There is an example in the "Interaction Pick Up 2-Handed" demo, in which the box can be picked up from any angle. The code for rotating the pivot is in PickUpBox.cs. It doesn't have to be a 2-handed pick-up, the logic of rotating the pivot is the same.

Best,

Pärtel

Welcome to RootMotion Q&A, where you can ask questions and receive answers from the developer of Final IK and PuppetMaster and other members of the community.

Post as a guest, create an account or login via Facebook.

Please use the correct category when you post your questions.

...