I’m using the below code to create a raycast laser, however the laser endpoint doesn’t end up at the hit point. Instead it goes behind my player in the opposite direction. I’ve confirmed the raycast is working properly through Debug.Drawray. What could be wrong?
IEnumerator PlatformerRaycastShot(){
Vector3 vectorToTarget = crosshair.transform.position - transform.position;
vectorToTarget.Normalize();
RaycastHit hit;
if(Physics.Raycast(transform.position, vectorToTarget, out hit, 5000, ~IgnoreMe)){
Debug.Log("2d player hit " + hit.transform.name);
Debug.DrawRay(transform.position, vectorToTarget * 1000, Color.green);
laserLine2D.gameObject.SetActive(true);
laserLine2D.SetPosition(1, hit.point);
}
yield return new WaitForSeconds(5);
lastShootTime = Time.time;
}