- Home /
Add force only to specific layer?
I have a raycast that applies forces to rigidbodies but I'd like it to apply different amounts of force depending on what specific object its hitting. In my case, I'd like it to apply a specific amount of force when its hitting an NPC as opposed to level props.
I can't use CompareTag because the NPC has several different colliders attached to its bones, each with their own tag. I was thinking I could just group all of those colliders into one layer and have the raycast check for that. So how do I do something like (pseduo code):
RaycastHit hit;
if (Physics.Raycast(ray,out hit)){
if (hit.rigidbody!=null || EnemyColliders Layer){
apply specific force
}
}
Answer by Nexgea · Mar 11, 2015 at 08:59 PM
I think u could just make there if statement saying
if(hit.transform.gameObject.layer = 2) //addforce just to objects with specific layer
Your answer
Follow this Question
Related Questions
Push an object opposite direction of mouse position 0 Answers
How to make some raycasts ignore a layer and others not? 1 Answer
How do I refer to a different object? 0 Answers
How do I use layermasks? 9 Answers
Raycast ignore layers except 1 Answer