Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello !

I need to indicate here that I want only to use 1 frame / 20 :
(for the animation and the recording "writer")

C#
	void FixedUpdate() {
		
		delta_time += Time.deltaTime; 

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

			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 (frame < forces_dup.Length) { 

				if (frame >= 1) {

						float delta_x = (((nv_data[59].positions[frame] - nv_data[59].positions[frame-1]).z)*0.001f);
					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);
					}
				}	

			}

				frame++; 	
		}

}


I tried to do that (and other things) :

C#
void FixedUpdate() {

    delta_time += Time.deltaTime;

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

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

                            Debug.Log (frame);

                            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 (frame < forces_dup.Length) {

                                    if (frame >= 1) {

                                            float delta_x = (((nv_data [59].positions [frame] - nv_data [59].positions [frame - 1]).z) * 0.001f);
                                            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);
                                            }
                                    }
                            }

                            frame++;
                    }
            }
}


But it doesn't run...



Thank you in advance for your help
Posted
Updated 20-Apr-15 20:30pm
v2
Comments
Sinisa Hajnal 21-Apr-15 4:08am    
Same advice as in your other question, add parameter to FixedUpdate(bool skipLines) and change third line into:
if (skipLines && (frame %20 == 0)) {}
Coralie B 21-Apr-15 4:15am    
Why to use a bool here ?
In all of lines of void FixedUpdate I want to use only 1 frame / 20.
Sinisa Hajnal 21-Apr-15 4:32am    
Then I'm totally lost. You have to use all lines in Start. You have to use 1 / 20 in FixedUpdate...and you do...what is the problem? They are separate methods that (it seems) don't interract. If this is the case you don't need bool, but (as I understood) you have to use all or 1/20 depending on where you call the method.
Coralie B 21-Apr-15 4:37am    
I have to use all of lines in void start.
I have to use 1 line / 20 (so 1 frame / 20) in void FixedUpdate.

But what I did in my code which appears in my question, it doesn't run. So I am searching a solution... But all things what I try , are wrong.

So have you got any ideas to do that ?

Sorry for my previous question "How can I make a different processig in the same code ?" I thought at this moment, that we can to do what I want in void start because I tried already in void FixedUpdate and I didn't arrive to do what I want.
Sinisa Hajnal 21-Apr-15 7:28am    
The code looks fine (I'm not going into the acceleration math, just conditions). Only thing I notice is that frame is member variable declared on the class which means it stays at its last value so if you enter FixedUpdate second time in the same instance, you don't start from 0.

You should move all variables that you don't need as member variables into the methods that use them. That is, if you don't use frame anywhere else, move its declaration into FixedUpdate method (that way it will always start from 0 among other benefits)

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