- Home /
Linerenderer doesn't match my ray.
So I have this code that I am experimenting with, and the inputs and everything works fine, although when I test my Line Renderer, the lines do not match with my Debug.DrawRay test.
Like this:
It gets worse the closer it gets to the origin too:
Here is my code:
void PreJump()
{
//Mouse Pos
Vector3 direction = Vector3.zero;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray)) {
//placeholder values
direction.x = ray.direction.x*50;
direction.y = ray.direction.y * 50;
}
Vector3 top = Calculator.GetTop(gameObject);
//lr is the linerenderer
lr.SetPosition(1, top);
lr.SetPosition(0, direction);
Debug.DrawRay(top,direction);
if (Input.GetKeyDown(KeyCode.Space))
{
jumpDirection = direction;
preJumpPhase = false;
Jump();
}
}
Any help would be appreciated!
Answer by hexagonius · Feb 17, 2017 at 10:40 AM
You're setting a direction as the position for the LineRenderer, which only consists of positions. assign positions only (the same as if you were using Debug.DragLine instead of DragRay)
Your answer
![](https://koobas.hobune.stream/wayback/20220612111237im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Moving a 3D object with 2D swipes 2 Answers
Bouncing Raycast "Laser" Not Working? 1 Answer
Smooth Movement on Geometry Collission? 0 Answers
Raycast from an objects co-ordinates 1 Answer
Only One LineRenderer Renders 0 Answers