Setting X-Scale based on position between 2 Points.

Hi guys,
Currently, I am trying to make a level editor that will spawn ground rotated and scaled to fit between 2 points. Currently, the object will spawn at the midpoint between the 2 points and will correctly rotate to point toward both points. I also have a variable that updates to be the distance between the 2 points. All I need next is to be able to scale the GameObject’s x scale to make it fit between the 2 points. Here is an image of what the scene looks like right now with my tool so far:

Here is some of my code thus far: blockObj.transform.position = midPoint; blockObj.transform.rotation = Quaternion.Euler(blockObj.transform.rotation.x, blockObj.transform.rotation.y, direction); blockObj.transform.localScale = new Vector3(length, 1, 1); where midpoint is the midpoint on the image, length is the distance between the 2 points, and direction is the Tangent angle between the 2 points (code to find direction: direction = Mathf.Atan2(rightEnd.y - leftEnd.y, rightEnd.x - leftEnd.x)/Mathf.PI*180;).

If I understand what you intend to do, I think you should :

  1. Calculate the initial length of your GO (when it’s scale is 1), let’s name it initLength
  2. Make a ratio with your length distance
  3. Finally you obtain : xScale = length / initLength