I have a character that the player controls. He has a collider trigger on him. I am trying to kick around blocks when his collider comes into contact with a block’s box collider. If I happen to hit the blocks when they are moving(falling or being moved in some other way) the OnTriggerEnter event is triggered but if the boxes are motionless, the event is not triggered. I am stuck and cannot figure out why this is happening.
I think it may be happening because the blocks are always in contact with the ground when they are motionless so any collision events with other objects are not triggered.
I hope that my question is clear and thanks for any help that you can give me.
You need a case statement or an if statement to determine ‘what’ or ‘which’ object has the trigger enter been triggered by.
I do check to see if it is the blocks that I am hitting. The event is just not triggering at all when I come into contact with a motionless block.
Would you mind posting your player collision check code and your block collision check code (just that section, nothing else)
This is the code on the character to detect when he hits blocks. I do not have code on the blocks to detect collision.
function OnTriggerStay (hit : Collider)
{
var body : Rigidbody = hit.collider.attachedRigidbody;
// no Rigidbody
if (body == null)
return;
var bodyLayerMask = 1 << body.gameObject.layer;
if ((bodyLayerMask pushLayers.value) == 0)
return;
var explosionPos = explosionBlock.transform.position;
if (hit.rigidbody)
{
hit.rigidbody.AddExplosionForce(power, explosionPos, 0, 0);
}
}
Based on that code, it looks like it is not seeing its rigidbody, prior to returning out of the routing, throw a message to the console saying “no rigid body found”. Since you are breaking out of the routine at this point, it is the only thought I have at the moment.
Or it has something to do with your layer checking. I know why you are doing the check, but remove the check for a moment and see if it kicks the item or not.
Removing that check does not help. The collision function is never called when you hit a motionless block. I put an output message in the first line of the function and it is never called when you hit a motionless block. I think it’s because the blocks are already colliding with the ground and they aren’t triggering any other collision events.