Change direction of Linerenderer with RaycastHit on layer


I’ve been making a simple topdown shooter. It works fine, when I shoot I move slower and face the direction i’m shooting, but when I try to hit a target that is standing a bit higher on the Y axis, Everything goes wrong. The linerenderer focuses perfectly on the object at the beginning, but when I start moving the line itself moves away from the object or seems to even be above it for some reason?

Here is the code:

Floorhit is already called in the Awake function

	IEnumerator RenderTracer(Vector3 hitPoint){
		Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
		RaycastHit floorHit;
		float camRayLength = 100f;

		if (Physics.Raycast (camRay, out floorHit, camRayLength, floorMask)) 
			hitPoint = floorHit.point;
			tracer.enabled = true;
			tracer.SetPosition(1, spawnBullet.position);
			tracer.SetPosition(0, spawnBullet.position + hitPoint);
			yield return null;
			tracer.enabled = false;

Does it have something to do with the camRayLength? I can’t seem to get the right thing to do here.

Ok, first check that your lineRenderer is using World Space (it should, but still).

Now, you are drawing a line from spawnBullet.position - I don’t know where that is but I assume it is your bullet’s position -
to spawnBullet.position + hitPoint.

I do not think you want to draw a line to spawnBullet.position + hitPoint.
You maybe want to draw a line to hitPoint? It’s not very clear.

(Also, why are you using a coroutine here? Seems unnecesary).