Hi, I am wondering, how would I see the x,y,z coordinates of where the raycast hits on the object. I need to do this so if the player shoots a zombie in the head, it will do something different (blow it head off)
Use InverseTransformPoint from the RaycastHit.point.
–Eric
Could yo give an example? Or would it be
like:
var hit : RaycastHit;
if(Input.GetButtonDown("Fire1") Physics.Raycast(transform.position, transform.forward, hit, 1000) {
if (hit.gameObject.tag==NPC hit.point == transform.InverseTransformPoint (0,10,0)) {
BroadcastMessage ("ApplyHeadshot");
}
}
Something like that? And if so, is there a way to get an approx hit area? Like, from (0,0,0) to (1,4,2)?
The InverseTransformPoint should be from the object that you’re hitting. Also you’d want to check a range (it will never be exactly equal to (0,10,0) ), like if the y value is greater than 1.6, or wherever the head is at.
–Eric
I dont get it, how should I put it on the object, and have the raycast hit refer to it? An example would help.
Instead of “hit.point == transform.InverseTransformPoint”, which is getting the inverse transform point from the object doing the raycast, use “hit.point == hit.transform.InverseTransformPoint”, which gets it from the object you’re hitting.
–Eric
OH! I see… hit.transform… I forget some stuff like that sometimes
I will test it later, now I am trying to model a BullSquid… ![]()