I have a object moving at extreme speeds (around 50k in unity velocity units), so I used DontGoThroughThings to make sure it doesn’t pass through other objects.
The problem is I can’t get trigger OnCollisionEnter. I suspect this is because of the extreme velocity except DontGoThroughThings seems to fix that. (The code seems to return the object to its previous position until the engine detects a collision)
The object is spawned at the camera and hurled by an impulse using this code. The OnCollisionEnter function is near the bottom and consists only of a single print function.
#pragma strict
var projTemplate : Transform;
var muzzleForce : Vector3;
private var startTracking = 0;
private var trackerTarget : Transform;
function Start () {
if (muzzleForce == Vector3.zero)
muzzleForce = Vector3.forward * 1;
}
function Update () {
if (Input.GetButtonDown("Fire1")){
var newProjectile=Instantiate(projTemplate,transform.position,transform.rotation);
newProjectile.rigidbody.AddRelativeForce(muzzleForce,ForceMode.Impulse);
startTracking=1;
trackerTarget=newProjectile;
}
//if (startTracking)
//printVel(trackerTarget);
}
function OnCollisionEnter(collision:Collision){
print("Bazinga");
}
function printVel(newProjectile:Transform) {
print ("Velocity: " + newProjectile.rigidbody.velocity.ToString());
}