LineRenderer doesn't go to Hit.Point
My LineRenderer doesn't go to exactly hit.point, it goes to a few units below it.
I know this is because of some funkery involving world and local space, but I'm not sure how to fix it...
if (bulletTrail != null && firePoint != null)
{
LineRenderer l = Instantiate(bulletTrail);
l.transform.SetParent(firePoint.transform);
l.SetPosition(0, firePoint.transform.position);
l.SetPosition(1, hit.point);
Destroy(l.gameObject, .1f);
}
Any ideas? Thanks!
Answer by streeetwalker · Apr 05, 2020 at 05:30 AM
Hi @Razputin, make sure your LineRenderer component is set to use World Coordinates. If you do that then parenting it to another object will have no affect on the line's position point locations.
if you do that and it is still offset, then your hit point is not where you think it is, or you have something else going on.
Debug.Log( "Hit point = " + hit.point + " > Line Pos = " + l.GetPosition( 1 ) ); `
to verify they are at the same location.
Thanks, but my issue stems from the fact that I want it to be in local space so that it follows the firePoint when moving.
While this may not be realistic it looks better the way my game is laid out.
Is it possible to get an accurate hit location while in local space?
Yes, I believe you get the offset to the target hit point and add/subtract it to your line point, or there is a local transform function on your parent object, and you can use to transform global to local coordinates. I don't have it off the top of my head, so see the documentation on the Transform class.
Your answer
Follow this Question
Related Questions
How do I destroy particles with raycast? 0 Answers
Check if position is inside a collider 5 Answers
Determining point coordinates on a plane for a known normal 1 Answer
How do I make my raycast look up and down? 0 Answers
Raycast hit 2 Answers