public class ChangeDirection : MonoBehaviour {
public bool movePositive = true;
// Update is called once per frame
void Update () {
// CHECK IF MAX REACHED AND MOVING POSITIVE DIRECTION
if (this.transform.position.y <= 4f && movePositive) {
// MOVES IN POSITIVE DIRECTION
this.transform.position += Vector3.up * Time.deltaTime * 5f;
}
else {
movePositive = false;
}
// CHECK IF MIN REACHED AND MOVING NEGATIVE DIRECTION
if (this.transform.position.y >= -4f && !movePositive) {
// MOVES IN NEGATIVE DIRECTION
this.transform.position += Vector3.down * Time.deltaTime * 5f;
}
else {
movePositive = true;
}
}
}
NOT C-SHARP QUESTION EXACTLY - I NEED TO IMPLEMENT A BOOL LOGIC IN PYTHON The code above moves an object back and forth within specified limit making one bool switching True and False, Hits the max and moves in negative direction and hits the min and moves in positive direction.
But as you can see in the image, I can't do the same thing with the same logic. How can it be implemented in Python script with Animaton Node - Blender?
Adding the code extra if you have problem with image
move_pos = True
if input_x < 20 and move_pos:
input_x += 1
else:
move_pos = False
if input_x > -20 and not move_pos:
input_x -= 1
else:
move_pos = True
output_x = input_x