# vector for ball velocity

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

## Recommended Posts

shotTime - time between pressing button "D" and releasing button,

rigthTime - time between pressing button "RIGHT" and releasing button

#define MAX_SPEED             27.7777f //[m/s] ~= 100km/h
#define MAX_KICK_THRESHOLD    2000     //[ms]

How to write general algorithm for example like this:
- When only "D" is pressed then vector must have direction (0,1,1),so it has angle 45 over axis Z.
- When "D" pressed and "LEFT" and the delay of pressing LEFT and D is the same then vector is (-1,1,1)
- When "D" pressed and "RIGHT" and the delay of pressing LEFT and D is the same then vector is (1,1,1)
- When "D" pressed and UP and the delay of pressing UP and D is the same then vector is (0,1,0)
- When "D" pressed and DOWN and the delay of pressing DOWN and D is the same then vector is (0,0,1)

In additional to above output vector must have legth in relative to MAX_KICK_THRESHOLD  and MAX_SPEED, so when delay of pressing is 1 [s] then the speed should be 50km/h so lenght of the vector should be 27.7777f/2.

Here is my algorithm but according to my calculation it doesn't generate the right output data:
void Ball::kick(DWORD shotTime, DWORD rightTime, DWORD leftTime, DWORD upTime, DWORD downTime)
{
if(shotTime > MAX_KICK_THRESHOLD)
shotTime = MAX_KICK_THRESHOLD;

//calculate V parameters (length of the vector and coordinates)
float length = MAX_SPEED * shotTime / MAX_KICK_THRESHOLD;

float upTimeF = static_cast<float>(upTime) / static_cast<float>(shotTime);       //0..1
float downTimeF = static_cast<float>(downTime) / static_cast<float>(shotTime);   //0..1
float facYZ = upTimeF - downTimeF;
facYZ = d3d::DEGREE_45 + d3d::DEGREE_45 * facYZ; //angle
D3DXVECTOR3 up = D3DXVECTOR3(0, length*sin(facYZ), length*cos(facYZ));

float leftTimeF = static_cast<float>(leftTime) / static_cast<float>(shotTime);   //0..1
float rightTimeF = static_cast<float>(rightTime) / static_cast<float>(shotTime); //0..1
float facXZ = leftTimeF - rightTimeF;
facXZ = d3d::DEGREE_90 + d3d::DEGREE_45 * facXZ; //angle
D3DXVECTOR3 left = D3DXVECTOR3(length*cos(facXZ), 0, length*sin(facXZ));

D3DXVECTOR3 V = up + left;
}

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 23
• 42
• 75