Okay, so I have some items that the player can pickup/drop. I need the items to be 'pickupable' just on triggerstay, and be dropped (and fall to the floor) on key press.
I have a box collider set to trigger on the item so that I can pick it up, but how do add a rigidbody and another collider so that it has gravity? I tried just that- adding another box and rigidbody, but then I can't pick it up anymore. I also tried to add an empty child object with a box collider intead so that I could have a rigidbody, but I still couldn't pick it up anymore. I thought it was because the new pysical collider was bigger than the trigger box, but even after making the pysics box smaller, no go.
How can I set this up?
Also, I need the physical box collider to be disabled when held- the player is blocked from moving properly when holding another box collider in their hand
thanks for any help!
2 Answers
2
The moving trigger problem is very weird...and ANNOYING. Thanks guys for your help. I guess I am stubborn though, because I found a work around for a moving trigger:
If you want an object to both be a trigger and have pysics, You can have two colliders: the first collider must not be set to a trigger, then add your rigidbody, then add a second trigger(I used a sphere collider) and make it envelope the first collider, and set THAT to a trigger. For some reason, if you mess up that order of operations, the trigger will not be recognized anymore by the engine.
On a side note, the item when held was blocking movement to the player because of the active boxcollider. I tried to set it to a trigger just when equipped (and vise a versa when dropped), but again for some reason, it would only work one time only. SSOOOOO...
I dropped setting it to a trigger/not and added this bit of code
function Start() {
ignoreCollision("Player");
}
function ignoreCollision(tag: String) {
var objects = GameObject.FindGameObjectsWithTag(tag);
for (o in objects) { if (o.GetComponent("Collider") && o != gameObject) Physics.IgnoreCollision(collider, o.collider);
}
}
There are problems with moving triggers not sending trigger messages, so my suggestion would be to use OnCollisionEnter instead. If you are stubborn still, try making a child object that has the trigger. But I doubt you'll get it working. It will work in some cases (such as something walking into the trigger) but not in other cases (such as the trigger "walking into" something).
THIS IS THE ANSWER I WAS LOOKING FOR. Thank you holy crap. I thought I was going insane. Why doesn't the original collider work? Why is the order important? I am too new to this and I don't understand. Either way, thank you for posting this.
– greysonwarnerbuilt