✅ Math problem related to drawing a line renderer relative to an object in Unity

If I click on my cube and drag, the line renderer draws in the opposite direction of the cube as expected. If I click to the side and drag, the line is now out of place. I want the line to always behave as if the click began at the center of the cube. Here is a photo of what these two scenarios looks like, first dragging down starting from the cube, next dragging down to the right of the cube: Here is the code: https://hatebin.com/jblqsjbqsl
2 Replies
dankmememachine
dankmememachine16mo ago
Whelp, Chat gpt4 is pretty neat, here is a solution I made by modding this script and consulting with the robot: https://hatebin.com/nznqdqzsrs Just to be clear again, this script shows an indicator of the trajectory that the object will take upon release of the mouse. But wherever you drag from the origin will now always be the player and the angle will always be relative to the object. If I drag under the object, the red line goes upwards in a straight line, if I drag downwards from 100 units to the right and 100 units high relative to the object, the red line goes upwards in a straight line.
Accord
Accord16mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.