- Home /
Fast object on collider not working
Hello,
I got a Problem with Fast Objects (ie. a Bullet) hitting a collider (crate or anything). I got this fix for the problem
http://www.unifycommunity.com/wiki/index.php?title=DontGoThroughThings
But its not working completly. It is now always hitting the box, but the hit effect (little explosion) is on a somewhere completly wrong postion, and I dont know how to fix that.
This is my script for the collision:
var deto : Transform;
function OnCollisionEnter(collision: Collision)
{
if (collision.gameObject.tag == "SteelBox") {
var detonate = Instantiate(deto, transform.position, Quaternion.identity);
// If I change it to var detonate = Instantiate(deto, transform.position, Quaternion.identity);
// It will hit but it looks like its detonating inside of the box.. so no solution -_-
Debug.Log("hit");
Destroy(gameObject,0);
}
}
This is the script for my shot:
public var bulletMesh : Transform;
public var bulletSpeed : float=1000;
public var delay : int = 10;
function Update ()
{
delay--;
if (delay < 1) {
if(Input.GetButton("Fire1"))
{
if(!bulletMesh || !bulletSpeed)
{
Debug.Log("[Shoot] 'bulletMesh' or 'bulletSpeed' is undefinied");
}
else
{
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var bulletCreate = Instantiate(bulletMesh, GameObject.Find("SpawnPoint").transform.position, Quaternion.identity);
bulletCreate.rigidbody.AddForce(transform.forward * bulletSpeed);
}
delay = 10;
}
}
}
I hope someone knows where the problem lies :/ Thanks in advance
I don't think using "DontGoThroughThings" is needed any more with 3.x. Back in the "old" days of 2.x Unity did not have proper collision detection to prevent objects going through objects. Now you can set the "collison detection" in the rigidbody component to a more CPU expensive one to prevent objects going through other objects.
So pretty much the above script is a "hack".
no, I think he's right, 'cause having small rigidbodies objects sometimes the collision fails, so it's really convenient to use the raycast solution(which is contained in the script mentioned)
Well it is not affected by the size of theobject. Even if I enable that its a continous dynamic object ( and the object to collider with) it doesnt change. I increased the size of the collider, optimised the speed, removed the dontgetthrough script, and will life with that i think =o If its fast it hit the object inside and the collusion on the surface of the object is not completly visible, if it is very fast, it goes through the object.
skinWidth does not change anything, regardless of the value =o
Answer by anwe · Nov 27, 2011 at 08:24 PM
Probably u have set the variable skinWidth in the "DontPassThroughThing.js" too high, try 0.1-0.2, otherwise u'll get this terrible error!