# 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.x = Math.cos(angle * degreesToRads);
direction.y = Math.sin(angle * degreesToRads);
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.

## closed as not a real question by Trevor Powell, thedaian, TetradJan 26 '12 at 7:25

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

• 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.