# Using Vectors for 2d animation [closed]

I've decided that it's best to start using vectors in my games instead of the
xPos += xSpeed and yPos += ySpeed approach.

I'm posting some of the code from my basic model class which handles movement logic in my game so that someone can tell me if I am using vectors correctly. I have a position, direction, acceleration and velocity vector. Here is some code, I can post more if needed:

model.update() and rotate() function

public function update():void
{
checkInput();
velocity.multiplyScalar(friction);
dispatchEvent(new Event(Event.CHANGE));
}

public function rotate(val:Number):void
{
angle += val;
direction.normalize();
}


and the checkInput() function

private function checkKeys():void
{
accel.set(0, 0);
if(keys[Keyboard.LEFT])
{
rotate( -5);
}
if (keys[Keyboard.RIGHT])
{
rotate(5);
}
if (keys[Keyboard.UP])
{
accel.x = direction.x * 0.8;
accel.y = direction.y * 0.8;
}
if (keys[Keyboard.DOWN])
{
accel.x = direction.x * 0.5;
accel.y = direction.y * 0.5;
}
}


Hopefully someone can tell me if I'm using vectors correctly by adding acceleration to velocity and to speed and also if I'm doing rotation the correct way or if there is a better way. Or anything anyone can suggest to improve would be great.

• Come on guys down votes with no comment are not helpful. – James Jan 25 '12 at 0:23
• There is no specific question here. – Tetrad Jan 25 '12 at 15:31

There's no "correct" way to do this. Using xPos += xSpeed and yPos += ySpeed is basically the same as pos.addVec(velocity). I suggest you use what you're comfortable with.
• You don't need to normalize your direction after the rotation calculation. It's a unit vector already.