Hi guys,
I’m trying to figure out how to properly carry items by player while respecting collisions between the item and obstacles.
Approaches I tried:
Update method approach - the movement is pretty smooth, no jittering but of course transform is often out of sync of physics, therefore it’s possible to push an object fast throught a wall or worse ground. Tried Physics.SyncTransforms() as well.
Fixed update method - the movement jitters considerably (I would need to significantly decrease fixed update time and it won’t completely fix the issue).
Spring joint or fixed joint method - the same issue as above - physics is automatically updated in fixed interval set in fixed update, so any joint jitters significantly when moved by player.
Also I’m afraid fixed update won’t help the situation when player carries an item an makes very fast movement (rotation) agains a wall. The collider will go through the wall despite the rigidbody is set to continuous dynamic.
Any ideas, tips, how to achieve this? I really cannot figure this out myself.
One idea was to force item drop when delta position of the carried item between last 2 frames exceeds some limit. Doesn’t work well, too bad experience for player.
I can provide more details or test scene or video if needed.
I assume you’re only needing this for large objects like crates and boxes but not small single handed objects. So what I have done in the past is use an empty child object in front of the character and have held objects chase that empty. If the object fails to remain within a set distance of the empty then it is simply dropped. This can be caused by collisions or the player moving too fast. Hope this helps.
You are right. I now tuned it in the way of a good compromise. Movement smoothness is acceptable.
Sharing the code for those interested / struggling with this as well.