Clamps value and returns a value not less than min and not more than max.

speed = 1000
# a is 20
a = clamp(speed, 1, 20)

speed = -10
# a is 1
a = clamp(speed, 1, 20)

 

  1. 최대, 최소값을 적용해야하는 것들(예: 속도, 가속도, 데미지, 혹은 UI에서 볼륨 설정 등)에 적용할 때 사용하면 유용할 듯 하다.
  2. if문을 사용하지 않아도 되므로 1~2줄의 코드라인을 절약할 수 있다.

 

 

<참고>
http://docs.godotengine.org/en/3.0/classes/class_@gdscript.html?highlight=clamp#class-gdscript-clamp

+ Recent posts