Skip to main content
added 672 characters in body
Source Link
jjimenezg93
  • 426
  • 3
  • 13

Maybe this math could guide you if as I understand your problem is that the horizontal and vertical lines "split" and you want them to stick together.

Having the distance between the two upper points of vertical lines, you can get the distance between them. Let's say d1.

The horizontal length of your upper line is length.

Then, d1 / length will give you the scale factor you need to "achieve" d1.

Numeric example:

distance = 10
length = 8

scaleFactor = 10/8 = 1.25

Then, 8 * 1.25 = 10.

I'm not completely sure this is what you expect, if it's not, please update your question with more details.


EDIT: In your updated code, I don't see your scaleFactor been used, your frontWall scale depends on translate, not on the factor. Besides that, this scaleFactor is calculated with scale.

What I tried to tell you to do is something more like the following:

Vec3 translate = positionX - other.positionX; //That's ok
float scaleFactor = translate.transform.x / frontWall.lengthX;
//Here, it's meant to use the length of the frontWall in its X-axis
Vec3 newScale = new Vec3(frontWall.lengthX * scaleFactor, localScale.y, localScale.z);

Excuse me for this code not being compilable, I've not been using Unity for a while now and I'm on my Smartphone.

Maybe this math could guide you if as I understand your problem is that the horizontal and vertical lines "split" and you want them to stick together.

Having the distance between the two upper points of vertical lines, you can get the distance between them. Let's say d1.

The horizontal length of your upper line is length.

Then, d1 / length will give you the scale factor you need to "achieve" d1.

Numeric example:

distance = 10
length = 8

scaleFactor = 10/8 = 1.25

Then, 8 * 1.25 = 10.

I'm not completely sure this is what you expect, if it's not, please update your question with more details.

Maybe this math could guide you if as I understand your problem is that the horizontal and vertical lines "split" and you want them to stick together.

Having the distance between the two upper points of vertical lines, you can get the distance between them. Let's say d1.

The horizontal length of your upper line is length.

Then, d1 / length will give you the scale factor you need to "achieve" d1.

Numeric example:

distance = 10
length = 8

scaleFactor = 10/8 = 1.25

Then, 8 * 1.25 = 10.

I'm not completely sure this is what you expect, if it's not, please update your question with more details.


EDIT: In your updated code, I don't see your scaleFactor been used, your frontWall scale depends on translate, not on the factor. Besides that, this scaleFactor is calculated with scale.

What I tried to tell you to do is something more like the following:

Vec3 translate = positionX - other.positionX; //That's ok
float scaleFactor = translate.transform.x / frontWall.lengthX;
//Here, it's meant to use the length of the frontWall in its X-axis
Vec3 newScale = new Vec3(frontWall.lengthX * scaleFactor, localScale.y, localScale.z);

Excuse me for this code not being compilable, I've not been using Unity for a while now and I'm on my Smartphone.

Source Link
jjimenezg93
  • 426
  • 3
  • 13

Maybe this math could guide you if as I understand your problem is that the horizontal and vertical lines "split" and you want them to stick together.

Having the distance between the two upper points of vertical lines, you can get the distance between them. Let's say d1.

The horizontal length of your upper line is length.

Then, d1 / length will give you the scale factor you need to "achieve" d1.

Numeric example:

distance = 10
length = 8

scaleFactor = 10/8 = 1.25

Then, 8 * 1.25 = 10.

I'm not completely sure this is what you expect, if it's not, please update your question with more details.