2
votes

I am having collision issues in various different cases. I will mention each of them and will wait for your help.

Case 1:

I have an object moving with characterController attached and moving through this plugin: http://u3d.as/content/hedgehog-team/...ck-buttons/2Uo

The objects to which the characterController collides are rigidbody with box colliders attached. Most of the times the collision works perfectly with natural collision effects such as falling of crates etc and OnCollisionEnter of the objects with rigidbody and box collider is called without any problem. But sometimes, this stops. There is no collision with objects no falling and OnCollisionEnter is not called.

I try debugging and searched on google but nothing helpful Found.

Case 2:

I have an object moving with characterController attached and moving with its "SimpleMove" function.

In this case none of the collision happen, no falling, no natural effect and no calling of OnCollisionEnter on objects which have rigidbody and box collider attached.

Please help fix this errors, I have been trying to fix these since 4 days but no luck, finally I am posting here. Will wait your replies.

Thanks. Have a great day!

2
Have you made sure that the Is Trigger button is unticked on your colliders?Savlon
Try to check other no-collision cases: 1) colliders are in non-colliding layers 2) colliders are excluded from interaction by Phyiscs.IgnoreCollision 3) some of colliders are disabled. I would run a test and wait until colliders began to misbehave, then pause the game and investigate the cases.game development germ

2 Answers

1
votes

Does the CharacterController have a RigidBody attached with 'isKinematic' checked?

0
votes

Add this script to your object :

#pragma strict

var layerMask : LayerMask; //make sure we aren't in this layer
var skinWidth : float = 0.1; //probably doesn't need to be changed
private var minimumExtent : float;
private var partialExtent : float;
private var sqrMinimumExtent : float;
private var previousPosition : Vector3;
private var myRigidbody : Rigidbody;
//initialize values
function Awake() {
   myRigidbody = rigidbody;
   previousPosition = myRigidbody.position;
   minimumExtent = Mathf.Min(Mathf.Min(collider.bounds.extents.x, collider.bounds.extents.y), collider.bounds.extents.z);
   partialExtent = minimumExtent*(1.0 - skinWidth);
   sqrMinimumExtent = minimumExtent*minimumExtent;
}

function FixedUpdate() {
   //have we moved more than our minimum extent?
   var movementThisStep : Vector3 = myRigidbody.position - previousPosition;
   var movementSqrMagnitude : float = movementThisStep.sqrMagnitude;
   if (movementSqrMagnitude > sqrMinimumExtent) {
      var movementMagnitude : float = Mathf.Sqrt(movementSqrMagnitude);
      var hitInfo : RaycastHit;
      //check for obstructions we might have missed
      if (Physics.Raycast(previousPosition, movementThisStep, hitInfo, movementMagnitude, layerMask.value))
         myRigidbody.position = hitInfo.point - (movementThisStep/movementMagnitude)*partialExtent;
   }
   previousPosition = myRigidbody.position;
}

And don't forget to specify which layer you want to detect.

Good luck !