Click here to Skip to main content
15,894,546 members
Please Sign up or sign in to vote.
1.89/5 (2 votes)
See more:
Hello !

The text file which is created in this code, is not good. I don't have the good values.

I suppose my problem is about this line :
C#
float delta_x = (((nv_data [59].positions [frame] - nv_data [59].positions [frame - 1]).z) * 0.001f);


I think it takes :
nv_data[59].positions[20]-nv_data[59].positions[19]
nv_data[59].positions[40]-nv_data[59].positions[39]
nv_data[59].positions[60]-nv_data[59].positions[59]
...


or :
nv_data[59].positions[20]-nv_data[59].positions[0]
nv_data[59].positions[21]-nv_data[59].positions[1]
nv_data[59].positions[22]-nv_data[59].positions[2]
...

or :
nv_data[59].positions[20]-nv_data[59].positions[19]
nv_data[59].positions[21]-nv_data[59].positions[20]
nv_data[59].positions[22]-nv_data[59].positions[21]
...


Instead of : (and it's it that I want)
nv_data[59].positions[20]-nv_data[59].positions[0]
nv_data[59].positions[40]-nv_data[59].positions[20]
nv_data[59].positions[60]-nv_data[59].positions[40]
...


I want to use only each frame / 20 .

Here the part of the code where it appears :

C#
void FixedUpdate() {

    delta_time += Time.deltaTime;

    if (frame < nv_data [0].positions.Length) {

                    if ((frame % 20) == 0) {

                            for (int k = 0; k < body.Length; ++k) {

                            if (body [k] != null) { 

                                            body [k].transform.localPosition = nv_data [k].positions [frame] / 1000; // This part is ok

                                    } else
                                            continue;
                            }

            Debug.Log("Frame_animation : " + frame); // I have 1 frame / 20 : 0 , 20 , 40 , 60 , ...

                            if (indice_3 < forces_dup.Length-1) {

                                if (frame >= 20) {

                    Debug.Log ("Frame_writer : " + frame); // I have 1 frame / 20 : 0 , 20 , 40 , 60 , ...
                                            float delta_x = (((nv_data [59].positions [frame] - nv_data [59].positions [frame - 1]).z) * 0.001f); // It's here that I think I have some problems
                                            vitesse = delta_x / Time.deltaTime;
                                            acceleration = (vitesse - ancienne_vitesse) / Time.deltaTime;
                                            ancienne_vitesse = vitesse;

                                            indice_3 ++;

                                            StreamWriter writer = new StreamWriter ("Masse-fois-Accelerations_FR_5Hz", true);

                                            using (writer) {

                                                    writer.WriteLine (Time.time + "\t" + 80*acceleration + "\t" + forces_dup [indice_3].x); // Here I don't have the correct values for 80*acceleration
                                            }
                                    }
                            }
                    }

                            frame++;
            }
    }


Thank you very much in advance for your help
Posted
Updated 4-May-15 9:51am
v5
Comments
Florian Braun 4-May-15 9:16am    
a very short guess: change "frame-1" to "frame-20"?? (in your marked line)
Coralie B 4-May-15 9:22am    
I tried but it doesn't run...
I had wrong result again
Coralie B 5-May-15 2:21am    
So it's correct this solution.
But at the end I had never the good result in my text file. Therefore, I supposed that the problem came from the line : float delta_x = (((nv_data [59].positions [frame] - nv_data [59].positions [frame - 1]).z) * 0.001f);
even though I put frame-20 instead of frame-1 .

In short, you gave me the good solution for this line. Thank you !
Florian Braun 4-May-15 9:27am    
did you try to set a breakpoint to that line to check whats inside all these variables?
Coralie B 4-May-15 9:38am    
No I didn't know how can I use breakpoint.
Actually I know to use it but I don't know how I can analyse the result.

I think it's not useful to tell you what exact values I much have because they are float, so there are a lot numbers. I know that I have not the correct values because I did this code in a different script. And I compared the both, and there was no connection.

1 solution

C#
void FixedUpdate() {

    delta_time += Time.deltaTime;

    if (frame < nv_data [0].positions.Length) {

                    if ((frame % 20) == 0) {

                            for (int k = 0; k < body.Length; ++k) {

                            if (body [k] != null) { 

                                            body [k].transform.localPosition = nv_data [k].positions [frame] / 1000;

                                    } else
                                            continue;
                            }

                            if (indice_3 < forces_dup.Length-1) {

                                if (frame >= 1) {

                                            float delta_z = (((nv_data [59].positions [frame] - nv_data [59].positions [frame - 20]).z) * 0.001f);
                                            vitesse = delta_z / (Time.deltaTime*20);
                                            acceleration = (vitesse - ancienne_vitesse) / (Time.deltaTime*20);
                                            ancienne_vitesse = vitesse;

                                            indice_3 ++;

                                            StreamWriter writer = new StreamWriter ("Masse-fois-Accelerations_FR_5Hz", true);

                                            using (writer) {

                                                    writer.WriteLine (Time.time + "\t" + 80*acceleration + "\t" + forces_dup [indice_3].x);
                                            }
                                    }
                            }
                    }

                            frame++;
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900