So I’m making a stray dog for my game. I’ve modeled it, rigged it, and animated it. Now, of course, I’m onto the development part. Where I program the German Shepard to remain idle, walk, run, and attack with python.
I’ve only got the idle segment complete. (Now I’m sure there’s other looking for answers for the same problem, so I’ll make this as broad as I can). Now, I’m wondering: how do I make the dog just do random things? Like scratch it’s head and randomly walk around in python?
I’ll go with the top one you listed. Since I like to keep the scrips consistent.
I was considering making a property called “Random”. It generates a random number from 0-10, since there are 10 misc idle animations. Then whatever integers it is, it plays that animation.
Ex:
1 is dog sniffing ground. 2 is dog scratching its head.
It generates 1, so then it plays the sniffing ground animation.
you can use a random int after each animation is played to get the next animation/behavior…hell you could even wieight them to give some a higher chance than others.
just use what I provided above…then a ‘switch case’…but geared to python…
if behavior == 0:#stand I assume
play animation function()#generic would have to write a function to control the animations...same for the following
elif behavior == 1:
play animation function()
elif behavior == 2:
play animation function()
else
play animation function()
This is very generic and not really optimized....it may be better to just change a property like add 'anim_state' as an int and then set up the animation bricks to play based on the property sensor...this would be fine for something simple, but can get a little crazy with complex logic.
here is a crude example, feel free to look at it…I’m not certain of your experience level I hope it is not too simple or even too complex…it is really basic stuff though.simple_states.blend (451 KB)
The random actuator can get you a random number in a property when activated.
You can setup the different states as states of the build-in state machine.
You can use the property with the random value to decide what state to switch to (or how long to wait till you do such a decision).
For example, in idle (or waiting) state you create a random number that represents the seconds when to decide the next action. So you start a timeout starting with that random number.
When the timer exceeds you calculate another random number (in a property). Then decide what to do. For example: 0 - wait again, 1 - walk to a random place, 2 - search for food …
You can even use this method at other states with different decisions: When waling and detecting an enemy the decide randomly to attack, hide or run away.
And yes, the exact same thing can be implemented via Python.