#### Archived

This topic is now archived and is closed to further replies.

# Vectors

This topic is 6795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there any way to calculate the life of a vector? I have created a function that will create a vector according to it''s speed, but I dont know how to calculate how long it has to go along for! example below. struct CVector { float X, Y, Z; int Life; // frames remaining }; void CreateVector(CVertex Cur, CVertex Dest, CVector *Vector, float Speed) { CVertex->X = (Cur.X - Dest.X) / Speed; CVertex->Y = (Cur.Y - Dest.Y) / Speed; CVertex->Z = (Cur.Z - Dest.Z) / Speed; CVertex->Life = ????? } With regards to the life, it would be better if the vector overshot the destination rather than not reach it. i know this is probably obvious, but please help! MENTAL

##### Share on other sites
The vector dissipates at whatever rate you want. Perhaps you can set it to 100 make it a float and go

#define Dissipation 0.95

Life = Life * Dissipation

Each frame you do this and it should go down to 0. If you want to do frames remaining, then caluclating the length of frames depends on the time. For instance, if you want the vector to last 3 seconds, you go

Life = 3 * CurrentFrameRate

That should make it last three seconds. Determining how long the vector lasts depends on what the vector is.

##### Share on other sites
The "life" of a vector has no meaning. A vector by definition is a magnitude & a direction. Its nothing more.

It sounds like what you might want to do is create a normalized vector (that is, a vector in the direction you want, with a magnitude of 1.0). At a higher level in the code, you would use the vector and the speed to calculate what you''re looking for.

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633417
• Total Posts
3011781
• ### Who's Online (See full list)

There are no registered users currently online

×