Public Group

# Distance over Time

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

## Recommended Posts

i am currently trying to model a projectile in Physx. I would like a force to be applied to this projectile every ten seconds. I have never used time functions before. I currently have access to time using
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&previousTime);

and with this i get the elapsed time. but i am not sure how to create a ten second counter. something that will just return tru when the elapsed time reaches ten seconds.

I know this is simple but for some reason my mind is stumped. i just need some one to potentially explain how this works.

thanks Edited by greenzone

##### Share on other sites
 // simplified pseudocode class Timer { public: Timer(int duration) { this.duration = duration; this.start = GetCurrentTime(); // replace GetCurrentTime() with whatever the right function is for your target API } void restart() { this.start = GetCurrentTime(); } bool finished() { return GetCurrentTime() >= this.start + this.duration; } private: int start, duration; }; 

Of course, you're free to ask questions, but I tried to make it uber simple and hopefully self explanatory.

##### Share on other sites

i am currently trying to model a projectile in Physx. I would like a force to be applied to this projectile every ten seconds. I have never used time functions before. I currently have access to time using
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&previousTime);

and with this i get the elapsed time. but i am not sure how to create a ten second counter. something that will just return tru when the elapsed time reaches ten seconds.

I know this is simple but for some reason my mind is stumped. i just need some one to potentially explain how this works.

thanks

If you are trying to model a projectile, why are you applying a force every 10 seconds? By the definition of a projectile, the only force acting on the projectile should be gravity. but gravity is a constant force... it is not applied every 10 seconds. If a force is being applied to the body other than gravity, than it is not a projectile and you are trying to model something different (imo).

Even if I assume you mean some sort of thrust (not a projectile) that is being applied to the "projectile", what sorts of thrust would occur every 10 seconds?

I imagine that it is possible that you want some sort of "homing" projectile which must constantly correct its angle to locate the target. In that context perhaps a 10 second interval for course correction would make sense. If that is the case then this link: http://answers.unity3d.com/questions/48836/determining-the-torque-needed-to-rotate-an-object.html may help

I only bring this up because from the statement of your problem it is possible that you may need to reconsider the approach.

Look at the PhysX documentation and look to see if you can find something about applying forces and impulses. I think this may help you.

##### Share on other sites
shadowisadog, your right i am setting up a homing missile and i need to correct the tangent velocity angle for the uniform circular motion to work correctly. I only wrote every seconds because i didn't have a precise time in my head lol. realistically it would be tenth or hundredth of a second depending on how fast the missile is moving. thanks for the link as well.

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 22
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631733
• Total Posts
3001927
×