- Home /
setting camera to hit.point returning null vector
I'm no mastermind, so maybe someone can tell me why my hit.point is returning a null vector and setting my camera.transform.position to vec3.zero/null this is being handled by an empty object and inside it's class this is the body of that class....e.g. the code that I've written, nothing spectacular, just need it to work. :)
public Transform cam;
public float lerp_factor = 0.25f;
public float cam_range = 10.0f;
private Vector3 v1;
private Vector3 v2;
private Vector3 temp;
private float dist;
RaycastHit hit;
void FixedUpdate()// 0.016 step interval..I think
{
// v1 & v2 are just vector3's
// dist is clarly just a float...all pretty clear I think.
// RaycastHit hit and other variables are all previously defined.
v1 = transform.position;
v2 = transform.position -transform.forward * cam_range;
dist = Vector3.Distance(v1,v2);
// debug for orientation visibility in game
Debug.DrawLine(v1, (transform.position + transform.right * 2), Color.yellow, 0.016f);
if(Physics.Linecast(v1, v2))//(Physics.Raycast(v1,v2, out hit, cam_range))// neither seems to be working
{
temp = hit.point;
Debug.DrawLine(v1, hit.point, Color.red, 0.016f);
}
else
{
Debug.DrawLine(v1, v2, Color.green,0.016f);
temp = v2;
}
//cam.transform.position = temp;// debug
cam.transform.position = Vector3.Lerp(v1, temp, lerp_factor);//temp;//
Debug.DrawLine(v1, v2, Color.green,0.016f);
}
Answer by nowherebrain · Nov 29, 2019 at 09:36 PM
ok, I realized I never returned the hit.info....obviously the reason I was returning a null vector.
Your answer
Follow this Question
Related Questions
How to have an object some distance above another object Locally? 1 Answer
Use OnTriggerEnter during a transform ! 0 Answers
Why is the ray cast pointing towards the origin of the scene? 4 Answers
Want to move object slowly to where the mouse clicks? 1 Answer
Adding rotation to Physics.AddForce(); ... Getting weird error? 0 Answers