2D TDS Raycast: Drawray vs Line Renderer.
Hello, still really green when it comes to coding. I'm making a 2D Top Down Shooter and one of my guns uses raycasting. I want to see a line in game view of where the bullet is going. It looks great when I use Debug.DrawRay. Its exactly what I want. As far as I understand though DrawRay is specifically for debugging and I believe I should be using a Line Renderer. However when I try to use a Line Renderer the line is way too wide, the color is fading like some kind of gradient, and I can't get the position where I want it. It seemed so simple when using DrawRay and the added level of complexity of using a Line Renderer just doesn't seem worth the trouble. Is there a simpler way? Or am I stuck with using a Line Renderer? Can I use DrawRay for the game? I know I can see it in Game View if I have gizmos on but will that work for the actual game?
Here is kinda what I have(try to ignore the irrelevant parts, sorry):
{
Debug.DrawRay(firePoint.position, firePoint.up * 10, Color.red, .5f); <--This looks great.
raycastLineRenderer.SetPosition(0, firePoint.position); <----This not so much
raycastLineRenderer.SetPosition(1, Player1.transform.position); <----This not so much
//RaycastHit2D hitInfo = Physics2D.Raycast(firePoint.position, firePoint.up);
//if (hitInfo)
//{
// Enemy enemy = hitInfo.transform.GetComponent<Enemy>();
// if (enemy != null)
// {
// enemy.TakeDamage(currentWeapon.damage);
// }
//}
}
Your answer
Follow this Question
Related Questions
Top Down Raycast 0 Answers
Trajectory (line renderer) not showing for some angles 1 Answer
RayCast2D and RayDraw errors 0 Answers
2D shooting script fixed camera 2 Answers
Raycast Troubleshooting 1 Answer