Half-Life Style Rigidbody Pickup System

Hey everyone,

Ive been messing around with different ways to achieve a Half-Life style rigidbody pickup system. If you’re not familiar, the character presses a button to have a physics object hover in front of him and can then drop it with another press. After a few hours of experimenting/ searching I have found there are two methods people seem to use, neither of which meet my requirements.

Firstly, people just make the object a child of the camera for the duration of the pick up, faking the pick up. This simple solution has numerous problems, one it looks artificial as hell as there isn’t any sway. Two, the object clips straight through objects which both looks terrible and breaks the game.

The second, people use rigidbody.movepostion to have the rigidbody move to a position in front of the player. This works better, but will still clip through objects most of the time.

Has anyone any better ideas/ solutions? I’ve pretty much hit a brick wall with this and can’t really continue my project until I figure it out.

Thanks,
Dan

Using a combination of Rigidbody.AddForce and increasing the object’s drag based on how far it is from the destination position should prevent any clipping issues and also give a slight sway to the object being carried.

I don’t know how I would use that. Sorry I’m new to scripting and I’m not sure how I would calculate what direction to add the force/ how to calculate the drag.

Here is a thread I started about this I started…two years ago??? My god how time flies. What was I even doing two years ago? Coding Half Life 2 object grabbers clearly.

I ended up using Forces, while setting the mass of any picked up object to a constant value (a fairly low one if I remember). This solves the problem of being able to bash other rigidbodies around with your grabbed object. Although you may want to do this, if you want your object to move as fast and precisely as Half Life 2’s, you need a fairly fast force that can turn it into a wrecking ball.

I’ve gotten a system up and running based on the same ideas from that thread, thanks! Im having major problems however, with something that might actually be a bug with unity. When a player stands on the object they are holding they float into the air, to counter this I simply check to see if the object collides with something drop it. However, the following code attached to a sphere is not called when the player stands directly on top of the sphere.

function OnCollisionStay (collisionInfo : Collision)
{
Debug.Log(“Impact”);
}

I simply don’t understand, the sphere is pushing the player up and I can see them visibly colliding, but no log message.

The Collision Matrix at the bottom of that page shows when collision messages are sent based on the types of colliders colliding.

Which one of those would a character controller fall under?

Good question. Test it and find out!