I need random ticks for a game I'm making. Is there a way I could do that? I don't want it based on the tick rate of my game (average 60 ticks per second) because I need random movement for a character. Maybe I could use some of Notch's code?
Asked
Active
Viewed 351 times
2
-
3What *exactly* do you mean by "random ticks"? – Jon Skeet Nov 28 '12 at 22:13
-
Don't you just want the character to move a random amount, including zero, every tick? You don't want "random ticks", you want random motion. – Dave Newton Nov 28 '12 at 22:16
-
@Dave Newton Random ticks to control random motion – user1610406 Nov 28 '12 at 22:23
-
2@user1610406 Not a helpful response to a valid concern. In any case, again, random ticks aren't what you want--your game loop is your game loop. You want the character to move based on your existing game loop a random percentage of the time. – Dave Newton Nov 28 '12 at 22:27
-
@user1610406 So what's the problem? Every game loop check to see if the character "should" move, either based on a random %, previous motion/direction, combination of the above, etc. – Dave Newton Nov 28 '12 at 22:29
-
@trashgod Thanks, that worked for me. I'm porting your comment into an answer. – user1610406 Nov 28 '12 at 22:47
-
+1 for responding positively to comments. – trashgod Nov 28 '12 at 22:51
2 Answers
0
You have two main choices;
- You can store a random value, and decrement it (reduce by one) every tick. when it reaches zero; perform your desired action, and assign a new random number to the variable. rinse and repeat.
- This effectively gives you a random psudo-tick, entirely within the contraints of the existing timing mechanism.
- Disregard the tickrate; randomised actions do not require randomised intervals, only randomised chance.
Basically, each tick you roll a chance of deciding on a new action, if the chance succeeds you choose a new action for the entity.- Its common to modify the chance based on how long they have been doing their current action; so that the longer an entity has been, say, 'sitting down', the more likely they will be to switch to something else.
You probably will also want to look up material on state-machines, as its a common way of implementing simple AIs for game characters (which seems to be what you are doing).

Textmode
- 509
- 3
- 18