function Go() {
horizontal = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
vertical = Input.GetAxis("Vertical") * speed * Time.deltaTime;
var pos : Vector3 = transform.position;
pos.x = Mathf.Clamp(pos.x + horizontal, -7, 7);
pos.y = Mathf.Clamp(pos.y + vertical, -7, 7);
transform.position = pos;
}
The link Lipis gave in comment indeed explains the Clamp
function. Basically it keeps the value within a certain range so with Mathf.Clamp(value, -7, 7)
, if value
is less than -7
, function returns -7
, bigger than 7
, function returns 7
, otherwise it just returns value
.
So by making sure we never set the value outside the allowed range we won't get jittering.