Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

Follow rigidbody center of mass

$
0
0
Hi, it's I while I'm stuck with this problem.
I'm creating an item picker system to let you pick up items, bring it with you, rotate etc...

What I need to do is let the item picked up following a transform point in word space, but not with item.transform.position but with its point of mass(basically an offset). Like this, if you move the point of mass, you move the item in the new position based on its centre of mass position.

I already did something working but I'm stuck in the updating continuously the point to new point.

itemTarget.position = Vector3.Lerp(itemTarget.position, raycastPoint.position - targetRb.centerOfMass, Time.deltaTime * followSpeed); Where **itemTarget** is the gameobject picked up, **raycastPoint** is the transform set in the middle of the item and **targetRb** is the item's rigidbody.

Everything works fine, and when I change the centerOfMass the item picked up it still works fine.

![screenshoot_1][1]

![screenshoot_2][2]

The problem is when I rotate the item works in weird ways because centerOfMass is local. I tried to apply the word position without success.

itemTarget.position = Vector3.Lerp(itemTarget.position, raycastPoint.position - targetRb.worldCenterOfMass, Time.deltaTime * followSpeed);

I tried to update the new position for one frame, but I need to update it continuously.

itemTarget.position += raycastPoint.position - targetRb.worldCenterOfMass; [1]: /storage/temp/149014-screenshot-12.png [2]: /storage/temp/149015-screenshot-13.png

Viewing all articles
Browse latest Browse all 536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>