Hi guys, yet another n00b question!
In my code, I have a weapon that shoots whenever you press the LMB. Problem is, it shoots about 700 times per second (which is my frame rate). I need it to shoot, wait for a specific amount of time, and then shoot again. I looked all over the forum, and couldn't find a thing. Yes, I used the almighty search function. Any ideas? They are all appreciated!
Ultran00b
Waiting for a specific amount of time
Waiting for a specific amount of time
Use the debugger, young Skywalker...
-
- Posts: 7
- Joined: Tue Oct 30, 2007 8:55 pm
When you shoot get the time, then when processing the input for the weapon firing, check that time against the current time and find the difference, if enough time has passed then allow the firing.
Example (this is off the top of my head so it would likely need modification to actually work):
EDIT: oh too late.... hope this helps anyway..
Example (this is off the top of my head so it would likely need modification to actually work):
Code: Select all
//variable declarations
u32 lastFiredTime = 0;
//When the weapon is fired (in the event reciever I assume)
if (device->getTimer()->getTime() - lastFiredTime >= X) //replace X with the time in milliseconds you want between
//shots
{
lastFiredTime = device->getTimer()->getTime();
//your code for firing the gun
}
"Surely we don’t need to waste resources on pathfinding; they just need to walk along the shortest route from one place to another." - EA Producer
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
^^^
Winner.
Ignore the link in the first reply, it's not really relevant to your problem.
Winner.
Ignore the link in the first reply, it's not really relevant to your problem.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
For my case, I use the time() method.
e.g
Note that the smallest unit of the time function is 1 second. Hope it helps
e.g
Code: Select all
#include <time.h>
time_t start;
time_t end;
time(&start);
time(&end);
if(start - end > 5)
//do some shooting action
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
That's not a good idea, because Irrlicht provides a timer concept which can also handle game pausing etc. And it's more accurate and better portable. Basically no weaknesses compared to simple concepts like time(). So avoid platform (or even default lib) routines if Irrlicht does provide things for you.