- Home /
The question is answered, right answer was accepted
Making a bubble level (not a game but work tool)
Hi, im trying to make a bubble level. But i'm having some issues. I got 2 objects where i check the difference in Z axis. I use this (psuede)code
movement = randomObject1.position.z - randomObject2.position.z;
bubble.transform.position = new Vector3(0f,0f,movement); //moves in Z direction
But the bubble keeps moving continuesly but i'm what I want is when the movement variable gets bigger/more/higher the bubble moves more to the left or right, but now it keeps moving continuesly with the speed it gets from movement. So my question is if you have any solutions for the movement. I maybe thought by adding forces or something but i have no clue how that works.
By the way.. this is a bubble level
Answer by ChrisJoosten · Jun 11, 2014 at 09:47 AM
Already fixed the problem I used standard transform.position and added forces against. This is my script.
void BubbleMovement(){
float xF1 = AdjustF1.transform.position.y;
float xF3 = AdjustF3.transform.position.y;
float movement = xF1 - xF3;
float zForce = 0.1f;
curPosZ = bubble.transform.position.z;
if (locked) {
if(movement >= 0.1f && curPosZ > minMoveZ){
bubble.transform.position = new Vector3(bubble.transform.position.x, bubble.transform.position.y, bubble.transform.position.z + (movement * Time.deltaTime / 50f) );
bubble.rigidbody.AddForce(0f,0f,-zForce, ForceMode.Force);
}
if(movement <= -0.1f && curPosZ < maxMoveZ){
bubble.transform.position = new Vector3(bubble.transform.position.x, bubble.transform.position.y, bubble.transform.position.z - (movement * Time.deltaTime / 50f) );
bubble.rigidbody.AddForce(0f,0f,zForce, ForceMode.Force);
}
}
}
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How can I make an object in my scene jump continuously? 1 Answer