[Closed] Orientation for Boids when Flocking
Hi Guys,
I have been putting together a flocking system which based largely on the work of Craig Reynolds. I have had success with nearly all areas except for the orientation of the boids. I cannot get them to point the way the cheeky things are flying. I am trying to set the orientation (Roll, pitch and Yaw) based on the velocity of the boid on the previous frame (old_vel) and the current velocity (new_vel).
I can post the code if people want, but in short, my function causes the boids to jump around in their orientation, and jump about in position too!!! So it is a complete failure. I think I am mis undstanding how to set the world rotation of an object (im using boid.rotation). Something is defintely going very wrong
Ideally I am looking to write a function with the inputs for the old velocity and the new velocity, and it returns the world rotation that the boid needs to be set at. If anyone could help me, or point me to page where I could learn. I am pretty good at maths, I should be able to grasp the maths involved here, but I am keen to understand it for myself. An example function or web page would be great, since I cold pick through it
Naturally, I will post up the flocking when it is finished. I have set up varibles that allow you to change nearly everything about the way the flock flies, so fish, birds, insects are all possible to simulate. Additionally you can get the flock to form the shape of geometry (fully animatable). Which can be used to get a V like formation for Geese, or to form shapes, faces…teapots etc. (you just tell the flock which geometry (editmesh) you want it to fly too). My computer is pretty average, and small flocks (<50) run perfectly smoothly (animation is baked out, during the simulation), but I have run flocks of 10,000 boids in overnight simulations, and there are no errors, it just takes time. Naturally after the simulation has been calculate, it then plays back in real time after that (since it is all keyframed out!!)
Any help would be greatly appreciated, this has fully got me confused. Thanks for your thoughts, and I hope you enjoy the script when I get it up and posted
Take care,
EverZen
Hi EverZen, sounds like an interesting script. I don’t have any direct solution right now, it would be easier if you posted the code that you think is failing. An easy way to set the direction of an object is to use obj.dir wich is the object local z-axis. So if you have the direction you want the object to go you can just say boid.dir = direction. This doesn’t solve the rolling etc though.
CML
The Example_Bank and Turn.ms script by John Wainwright which is included in the example scripts directory (3dsmax/scripts/examples) should get you on the way.
Cheers,
Martijn
Guys,
Thanks so much, you cannot really ask for 2 better answers than that! Martijn, I am going for the full bank and turn function for the flocking system. Rivendale, the obj.dir option is fantastic, and I can all ready think of a hundred other places where I could use that, and save so much time without having to worry about pesky rotations. Thanks guys!
With that little piece of knowledge I think I can wrap things up. I am going to optimise the code a little bit (it is very inefficient), and try and iron out some of the bugs, of which there are a lot at the moment. The interface will get a clean up, and then it is ready to go.
My email address is richjones@the-third-man.com.
Anybody, if you want to have copy I will send it over, just write to me (naturally open source) and you can tell me what you think, and if it works in any animations, then I would love to see them
It is not incredibly user friendly to set up flocks instantly, but that is partly since I have written everything into keyframable cusom attributes, so you can change the speed/goal drive/manuverability etc of the flock as it flies, at anytime (you have ful control). I will include a full user manual for those that are interested
Thanks again, great stuff,
Everzen