- Home /
Question by
StuwuStudio · Oct 30, 2015 at 08:57 PM ·
vector3directionraycasthitcookieshitpoints
RaycastHit direction and start position
Hi, i have little problem (with my english) with my RaycastHit, I use the Debug.DrawLine for see the start point and the hit point but the direction doesn't look good...
... 1. All line suppose to start from the middle of the "Ennemy" (I'm working on Zombie AI for halloween) 2. The line suppose to be flat on like this: / 3. Here's the code:
Vector3 front = transform.TransformDirection(Vector3.forward);
RaycastHit hitFront;
Vector3 back = transform.TransformDirection(Vector3.back);
RaycastHit hitBack;
Vector3 left = transform.TransformDirection(Vector3.left);
RaycastHit hitLeft;
Vector3 right = transform.TransformDirection(Vector3.right);
RaycastHit hitRight;
Vector3 p101 = transform.TransformDirection(Vector3.right + Vector3.forward);
RaycastHit h101;
Vector3 p201 = transform.TransformDirection(Vector3.left + Vector3.forward);
RaycastHit h201;
Vector3 p102 = transform.TransformDirection(Vector3.right + Vector3.back);
RaycastHit h102;
Vector3 p202 = transform.TransformDirection(Vector3.left + Vector3.back);
RaycastHit h202;
if(Physics.Raycast(transform.position, front, out hitFront)) {
Debug.DrawLine(hitFront.normal, hitFront.point, Color.red, 100f);
}
if(Physics.Raycast(transform.position, back, out hitBack)) {
Debug.DrawLine(hitBack.normal, hitBack.point, Color.red, 100f);
}
if(Physics.Raycast(transform.position, left, out hitLeft)) {
Debug.DrawLine(hitLeft.normal, hitLeft.point, Color.red, 100f);
}
if(Physics.Raycast(transform.position, right, out hitRight)) {
Debug.DrawLine(hitRight.normal, hitRight.point, Color.red, 100f);
}
if(Physics.Raycast(transform.position, p101, out h101)) {
Debug.DrawLine(h101.normal, h101.point, Color.green, 100f);
}
if(Physics.Raycast(transform.position, p201, out h201)) {
Debug.DrawLine(h201.normal, h201.point, Color.green, 100f);
}
if(Physics.Raycast(transform.position, p102, out h102)) {
Debug.DrawLine(h102.normal, h102.point, Color.green, 100f);
}
if(Physics.Raycast(transform.position, p202, out h202)) {
Debug.DrawLine(h202.normal, h202.point, Color.green, 100f);
}
I hope you understand me...
unity.png
(321.2 kB)
Comment