For a uniform scale of a vector's length/magnitude, you would have to multiply each component with the scaling factor.
1 2 3 4 5 6 7 8 9 10 11 12
|
D3DXVECTOR3 vec1(1.0f, 2.0f, 3.0f);
float scalingFactor;
//...
//determine your scaling factor based on the elapsed time
//suppose scalingFactor = 2.0f;
//...
vec1.x *= scalingFactor; // vec1.x * 2 = 2.0f;
vec1.y *= scalingFactor; // vec1.y * 2 = 4.0f;
vec1.z *= scalingFactor; // vec1.z * 2 = 6.0f;
|
So this would uniformly scale vec1 in all 3 dimensions, retaining direction (towards goalPosition) but scaling it's length / magnitude (doubling it, in the above example).
It's important to make sure you use the appropriate coordinate systems though. A vector can represent a 3D location in the coordinate system where it's initial point coincides with the origin for that coordinate system and the endpoint coincides with the vector's coordinate values.
So if we assume that the player position and the goal position are both expressed in world coordinates, a scaled down version of the goalPosition vector would not be the appropriate vector for adding to the player position (because the vector you want has it's initial point in the player position and it's terminal point in the goal position, while the goalPosition vector, if specified in world coordinates, has it's initial point in the world origin and it's terminal point in the goal position).
So you would probably have to do some coordinate system conversion as well, if all your values are in world coordinates. Usually, for 3D movement of a character, you would want to specify your movement in the character's local coordinate system (like in the direction of a cardinal half-axis, say +Z) and then convert to world coordinates per-frame to get the actual movement vector for that frame. By doing that, you would press "forward" on your keyboard (say, W) and depending on your character's orientation (specified by the rotation matrix for your character) the "forward according to character orientation" would be converted to world coordinates.