So I’m working on a beat-em-up type of action game where players can pick up boxes and throw them. However, I noticed that when a box was lifted over a character’s head, the box collider on the objects would actually stop a player from jumping (they would “hit their head” on the box and come right back down). So of course, I decided to disable all colliders on the object so that this wouldn’t happen, and instead extend the player’s own collider up to compensate.
Here was the relevant code:
class BaseItem extends MonoBehaviour
{
function PickedUp(parentTransform : Transform){
//For the box collider
this.collider.enabled = false;
//This item also has a trigger collider
var triggerCollider : CapsuleCollider = this.GetComponent(CapsuleCollider);
triggerCollider.enabled = false;
}
}
However, this was when I was experimenting with all my code inside of the BaseItem class.
When I decided to make a separate ThrowableItem class, I moved this code into the overridden version of the function:
class ThrowableItem extends BaseItem
{
override function PickedUp(parentTransform : Transform){
//For the box collider
this.collider.enabled = false;
//This item also has a trigger collider
var triggerCollider : CapsuleCollider = this.GetComponent(CapsuleCollider);
triggerCollider.enabled = false;
}
}
Now, for whatever reason, the colliders aren’t disabling… Even though the Unity editor says that they are disabled. That’s right… The Unity editor claims that the colliders have been turned off, even though the game still registers them being there.
I can even delete the colliders entirely off of the item mid-game and they will still register as being there. How is that possible? If they’re deleted, why are they still there?
I’m supposing this might have something to do with ThrowableItem being a child of BaseItem, but I can’t figure out why it happens this way and how to change it.
Any help is greatly appreciated!
Wait, what's this? I just realized that the object has a new SphereCollider inside of the box that came out of nowhere! And even stranger, it's not listed under the object's components, either! Have I come across a bug in Unity...?
– usagijojoI can't access the mysterious new collider through scripting, either... What on earth happened, I wonder?
– usagijojoAn image of the inspector settings and scene would help
– Linus