let previousHeight = null;
if (event.data.includes("Height : ")) {
let height = parseInt(event.data.replace("Height : ", ""));
console.log(height);
if (height !== previousHeight) {
previousHeight = height;
var newPositionY;
let newFeetScaleY;
if (height == 74) {
newPositionY = 22;
newFeetScaleY = 13;
}
if (height == 75) {
newPositionY = 29;
newFeetScaleY = 14;
}
if (height == 76) {
newPositionY = 36;
newFeetScaleY = 15;
}
if (height == 77) {
newPositionY = 43;
newFeetScaleY = 16;
}
if (height == 78) {
newPositionY = 50;
newFeetScaleY = 17;
}
if (newPositionY !== undefined) {
this.Table_Top[5].setLocalPosition(this.Table_Top[5].getLocalPosition().x, newPositionY, this.Table_Top[5].getLocalPosition().z);
// this.Table_Top[5].setLocalPosition(this.Table_Top[5].getLocalPosition().x, newThicknessPositionY = 0, this.Table_Top[5].getLocalPosition().z);
this.feet.setLocalScale(this.feet.getLocalScale().x, newFeetScaleY, this.feet.getLocalScale().z);
}
}
}
let previousThickness = null;
if (event.data.includes("Blade Thickness : ")) {
let thickness = parseInt(event.data.replace("Blade Thickness : ", ""));
console.log(thickness);
if (thickness !== previousThickness) {
previousThickness = thickness;
var newThicknessPositionY;
let newThicknessScaleY;
if (thickness == 4) {
newThicknessPositionY = -36;
newThicknessScaleY = 1.5;
}
if (thickness == 5) {
newThicknessPositionY = -72;
newThicknessScaleY = 2;
}
if (thickness == 6) {
newThicknessPositionY = -108;
newThicknessScaleY = 2.5;
}
if (newThicknessPositionY !== undefined) {
this.Table_Top[5].setLocalPosition(this.Table_Top[5].getLocalPosition().x, newThicknessPositionY, this.Table_Top[5].getLocalPosition().z);
// this.Table_Top[5].setLocalPosition(this.Table_Top[5].getLocalPosition().x, newPositionY = 0, this.Table_Top[5].getLocalPosition().z);
this.Table_Top[5].setLocalScale(this.Table_Top[5].getLocalScale().x, newThicknessScaleY, this.Table_Top[5].getLocalScale().z);
}
}
}
Problem Statement:
I have a table in my project that is controlled by two parameters: Height and Blade Thickness.
- When I adjust the Height first, everything works perfectly.
- When I adjust the Thickness first, it works fine as well.
- However, when I adjust the Height first and then the Thickness, the table’s position gets messed up.
- Similarly, if I adjust the Thickness first and then the Height, the position breaks again.
Issue:
The table’s position is currently static, meaning it’s always based on the initial starting point of the table. This causes problems when switching between Height and Thickness adjustments because the table doesn’t account for where its current position is when I switch.
What I need:
I need to make the table’s position dynamic:
- The Height should be able to adjust anywhere, and when I click on the Thickness, it should adjust from the current position.
- The Thickness should be able to adjust, and when I click on the Height, it should adjust correctly from that point as well.
- In other words, regardless of the order in which I adjust Height or Thickness, the table should always position itself dynamically based on where it currently is — not from its original position.
I want both adjustments to work independently and seamlessly, no matter the order in which I modify Height or Thickness.