I have a script that functions as a bullet hole generator for my gun. Here’s the code…
var bullethole : GameObject[];
var loaded : GameObject;
var gun : GameObject;
function Start () {
}
function Update () {
var fwd = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if(Input.GetButtonDown("Use") && Physics.Raycast(transform.position, fwd, hit, 999))
if(loaded.activeSelf)
if(gun.activeSelf)
{
Instantiate(bullethole[Random.Range(0,0)], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
}
}
but, the bullet holes sill hit colliders marked as triggers, and it makes it look like the bullet holes are floating in mid air. How do I fix this?
I’m not a pro, so I’m sorry if this is not what you are looking for, but I avoid collision of my projectiles by swapping my layers for my projectile and ignoring any collisions that are on the same layer.
Set layers using EDIT->PROJECT SETTINGS->TAGS AND LAYERS. I also setup the collision matrix with EDIT->PROJECT SETTINGS->PHYSICS. Hope that helps?
Thanks
King
2 Likes
You could put your colliers in an child gameobject and put it in a layer which ignores raycasts.
1 Like
Kiwasi
February 13, 2017, 6:20am
4
There is a toggle for ‘Raycasts hit triggers’. I believe it’s in the physics settings.
4 Likes
Pass your raycast a QueryTriggerInteraction, which excludes hitting triggers.
3 Likes
This toggle fixed it for me, Cheers!
MelvMay
February 14, 2023, 6:07pm
9
Please use the like button to show your appreciation. That way you don’t necro the thread for everyone.
Thanks.