Variables and ranges in javascript

Hi all. I have created an accelerated movement on my player object in game using the following code:

var rotVert:float = 1.0;
var horVelocity:float = 1.0;
var verVelocity:float = 1.0;
function Update() {

    horVelocity += 5 * Time.deltaTime; // increases horVelocity by 5 per second
    horMovement = Input.GetAxis("Horizontal") * Time.deltaTime * horVelocity; // gets axis for horizontal movement and applies velocity per second.
    transform.Translate(0, horMovement, 0); // moves by the value defined by the calculations in horMovement along the X axis.

    verVelocity += 1 * Time.deltaTime;  
    verVelocity -= 10; 
    verMovement = Input.GetAxis("Vertical");
    if (verMovement) {
    transform.Rotate(Vector3(0, rotVert, 0).right * verMovement * verVelocity);


I was wondering if it is possible to set a maximum value to horVelocity and verVelocity. I am familiar with Java but JavaScript is relatively new to me. Ordinarily I would use the < > symbols but i cannot find any reference to their use in this context. Can someone show me how to create a maximum value please?


You pretty much have the answer in your explanation :)

var maxValue : float = 10.0f;
var value : float = 0.0f;

function Update()
   value += 1;

   if (value > maxValue)
      value = maxValue;

Those < > symbols you refer to are actually called "relational operators". In the case of these two, < is a less-than operator and > is a greater-than operator.

Here is a pretty nice looking tutorial about relational operators in JavaScript:

Thanks, I will try this and post back. :-)