KodeAndGame / ProSewerPolo

Unity 3D sports game being developed for Robot Dice Game Jam
MIT License
3 stars 2 forks source link

Running into teammate's ball sometimes resets ball #60

Closed KodeAndGame closed 10 years ago

KodeAndGame commented 10 years ago

This happens because ball somehow gets taken out of the "valid play zone" though i'm not sure why that happens. May be a result of altering transform.scale instead of box collider size

KodeAndGame commented 10 years ago

I have set up a box collider that serves as a valid play zone. And I set up the OnTriggerExit function on the ball to detect if it's left this valid play zone. If it has, then reset the ball. Unfortunately it seems to also be running when I run into a ball someone else is holding (including teammates). This isn't immediately reproducible but I can get it to happen pretty consistently...

When I actually run into someone else's ball, I think it's raising the Y causing it to think it's left the playzone. But the Y on the playzone is high enough that this shouldn't be happening. In fact, when I test it in code, it's not passing the "has exited trigger" even though the callback is being called. The way I'm testing that in code is by checking the position of the ball against the bounds of the collider:

if(collider.GetComponent<BoxCollider>().bounds.Contains(transform.position))

for that to return true, means the ball is inside the bounds of the box. And it does return true even though this code is all inside of the OnTriggerExit function

That's what I have so far. I think it's some sort of Unity bug. Probably works better with a mesh included or something.

KodeAndGame commented 10 years ago

Changing the OnTriggerExit to the following code works as a workaround. It'll have to do for now:

void OnTriggerExit (Collider collider) {
        if(collider.tag == ValidPlayZoneTag && !collider.GetComponent<BoxCollider>().bounds.Contains(transform.position)) {
            Reset ();
        }
    }