Search Unity

LineRenderer and CircleCast not matching up over distance

Discussion in '2D' started by Fariel, Apr 28, 2017.

  1. Fariel

    Fariel

    Joined:
    Feb 9, 2013
    Posts:
    29
    I'm having a weird issue that doesn't make sense to me. I have a ship that shows a guide of where it is going to shoot. It does this by setting the start position of a line renderer to it's position, then setting the second position of the line renderer to it's position plus transform.up (it's forward orientation in 2d) multiplied by 999.

    This gives me a 999 unit line showing where it's laser is going to go. Now, when it fires, it does the same thing. It shoots a circle cast from it's transform, in the direction of transform.up (which, again, is it's forward orientation in 2d space), with a width of it's laser (0.21 is the radius) and has a distance of 999. This SHOULD cover the exact same space as the LineRenderer, but it doesn't!

    Now, I happen to know that the problem is the LineRenderer, and not the circle cast. If I move directly away from the ship that shoots, the guide laser starts to move to the side of the player, but the laser still hits the player. So the CircleCast is working as intended, but for some reason the line renderer doesn't go "straight."

    The only explanation I can come up with is the difference between the LineRenderer taking an absolute position, and the CircleCast taking a direction. I don't know why there would be a difference mathematically, though! They should end up as the same spot.

    Any kind of explanation would benefit me fantastically.

    You can see the full source code of the ship over at my Answers question here: http://answers.unity3d.com/questions/1344984/linerendered-raycast-not-matching-over-distance.html

    Also, you can download the game and witness the problem for yourself here: https://unibear-studio.itch.io/eat
     
  2. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    I'm hitting a similar problem. Is it the same in your case? Have you resolved it?

    https://files.catbox.moe/t5z2oq.png

    The hit.point from CircleCast is off to the side, so when the LineRender is set using that point, it's not "straight", not the same direction as the CircleCast
    So the desired point should be close to the hit point but keep the same direction as the CircleCast, does anyone have any idea how to achieve that?
     
    Last edited: Oct 20, 2020