Answer the question
In order to leave comments, you need to log in
How to ignore BoxCollider?
Hello.
Who knows / encountered how you can ignore colliders when using
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
//check if ray hits something
Vector3 targetPoint;
if (Physics.Raycast(ray, out hit))
{
Debug.Log("gameobject name " + hit.collider.gameObject.name);
Debug.Log("gameobject point" + hit.point);
targetPoint = hit.point;
}
else
targetPoint = ray.GetPoint(75); //Just a point far away from the player
//Calculate direction from attackPoint to targetPoint
Vector3 directionWithoutSpread = targetPoint - attackPoint.position;
//Calculate new direction with spread
Vector3 directionWithSpread = directionWithoutSpread + new Vector3(x, y, 0); //Just add spread to last direction
GameObject currentBullet = Instantiate(bullet, attackPoint.position, Quaternion.identity);
Debug.Log("directionWithSpread " + directionWithSpread);
currentBullet.GetComponent<Rigidbody>().velocity = directionWithSpread * shootForce;
Answer the question
In order to leave comments, you need to log in
Either put your objects with large colliders in the Layer and disable interaction with this layer for bullets, or if you need bullets to hit the model (and not into an empty place that is closed by the collider), then you need to make your own collider from small cubes that will cover your model
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question