- Home /
My Raycast on awake fires and will not change Help!
The Draw line Debug works in its Direction. The statement is called. But when it hits an object that it was not looking at during awake it says it hit on the old object in Debug.Log(hit.transform.name); How do I change what Hit is?
public void ShootTracerPoint()
{
Debug.Log("Fired!");
RaycastHit hit;
if (Physics.Raycast(FirePoint.transform.position, FirePoint.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
Instantiate(GrandTarget, hit.point, Quaternion.LookRotation(hit.normal));
}
when it hits an object that it was not looking at during awake it says it hit on the old object in Debug.Log(hit.transform.name);
Not to sure what is meant about the above. Are you trying to draw the debug ray exactly how the raycast was shot?? Because you pass a different start point and direction to debug.drawray and the raycast. If it’s supposed to be the same, pass the same start position and direction.
Anytime you raycast and return a Collider via RaycastHit, you will return the hit collider. Not sure what you mean by how to change what Hit is..
You are casting a ray forwards from FirePoint, a distance of range.
The hit will be whatever collider it hits first along that ray.
What is FirePoint and how are you setting its value? If you just set it in Start(), it'll always fire the same ray, and unless colliders are moving, will always return the same hit.
Do the objects you are expecting to hit have a collider component?