Sign in to follow this  
spider853

Air Drag Problem - Oscilation

Recommended Posts

Hi, I'm implementing a airplane game but I have a problem with the drag force,
For now (testing) I'm using only 2 forces
FinalForce = Thrust + Drag
Acceleration = FinalForce/mass
Velocity += Acceleration
Position += Velocity

The problem is that Drag keeps adding values to the acceleration and the object is oscillating forward and backward.

Here is my implementation:

[code]

float speedSQ = cml::dot(velocity, velocity); //Squared speed
if (speedSQ > 0.0) { // If applied to 0 then normalize gives #Inf
cml::vector3f normVel = cml::normalize(velocity); //Normalized Velocity
cml::vector3f Fd = (normVel * -1.0) * (0.1 * speedSQ); // Reverse Velocity normal vector multiplied by ConstDrag * speed^2
std::cout << velocity[2] << " " << Fd[2] << std::endl; // Debug output
AddForceVec(Fd); //Add the drag force
}

//Update Transform
acceleration = vecForce / mass;

velocity += acceleration * _dt;

// Adds the velocity
cml::matrix44f_c transMat;
cml::matrix_translation(transMat, velocity * _dt);
transform *= transMat;

[/code]

Thrust add:

[code]
//on Key Up
player.AddForceVec(cml::vector3f(0,0,1));
[/code]


I've tried different constants, different arrangements of code but still

Here is a debug output from (std::cout << velocity[2] << " " << Fd[2] << std::endl; // Debug output)

[code]
//Velocity | DragForce (All in Z)

0.1 -0.001
0.2999 -0.008994
0.598901 -0.0358682
0.994314 -0.0988661
1.47984 -0.218993
2.04347 -0.417577
2.66534 -0.710403
3.21617 -1.03437
3.66356 -1.34217
3.97674 -1.58144
4.13177 -1.70715
//Releasing the Thrust
4.11608 -1.69421
3.93098 -1.54526
3.59135 -1.28978
3.12274 -0.975149
2.55661 -0.653628
1.92513 -0.370612
1.25658 -0.157899
0.572241 -0.032746
-0.115371 0.00133105
-0.802851 0.0644569
-1.48388 0.220191
-2.1429 0.459202
-2.75599 0.75955
-3.29313 1.08447
-3.72183 1.3852
-4.012 1.60961
-4.14121 1.71496
-4.09892 1.68012
-3.88863 1.51214
-3.52712 1.24406
-3.0412 0.92489
-2.46279 0.606536
-1.82374 0.332601
-1.15142 0.132576
-0.46584 0.0217007
0.221906 -0.00492424
0.90916 -0.0826573
1.58815 -0.252222
2.24192 -0.502618
2.84542 -0.809641
3.36796 -1.13432
3.77707 -1.42663
4.04352 -1.635
4.14646 -1.71931
4.07748 -1.66258
3.84223 -1.47628
3.45936 -1.19672

[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this