   Wandering steering behaviour problems
  Hi I'm currently working on autonomous characters and simulated motion I'm currently working on random movement...or wandering if there are any who have tried this before you know what I'm referring too. I have a 3d space to work with, but I started simple and only attempted it in 2 planes, the x and y. problem is it doesn't look right. it wanders... but seems to continuously travel in the x direction while doing it and never goes back on itself or wander's at an angle greater than 90 degrees relative to the origin so really it kind of randomly oscillates. you can see hereand here is the code that does itwander algotirhmFvector Flocking::wander( PointEntity *flockMember ){    float wanderR = 160.0f;    // Radius for our "wander circle"    float wanderD = 600.0f;    // Distance for our "wander circle"    float change = 0.95f;float theta = (2.0f * ((float)rand() / (float)RAND_MAX) - 1.0f);// Randomly change wander thetawanderTheta += theta; if( wanderTheta > change )wanderTheta = change;if( wanderTheta < ( change * -1 ) )wanderTheta = ( change * -1 );    // Now we have to calculate the new location to steer towards on the wander circleFvector circleloc = flockMember->get_pEntityVelocity( );  // Start with velocityif( circleloc.length2( ) == 0 ){circleloc = Fvector( 0.1f,0.1f,0.f );}    circleloc = circleloc.getUnit( );// Normalize to get heading    circleloc *= wanderD;    // Multiply by distancecircleloc += flockMember->get_pEntityPosition( );// Make it relative to boid's location   Fvector circleOffSet = Fvector( wanderR*cos( wanderTheta ), wanderR*sin( wanderTheta ),0.f );    Fvector target = circleloc + circleOffSet;    Fvector steering = steer( target,flockMember,false );return steering;}here is where the return from the wander is appliedFvector targetPos = Fvector( 0,0,0 );Fvector path = wander( flockElements );flockElements->set_pEntityAcceleration( flockElements->get_pEntityAcceleration( ) + path ); Fvector meToTarget = targetPos - flockElements->get_pEntityPosition( );//change in velocity is accelerationdeltaVel = flockElements->get_pEntityAcceleration( );newVel = currentVel + deltaVel;//the new velocity of the entity is the current plus the change in velocity//newVel = newVel.limit( 20 );//limit the velocity to the max speed newPos = flockElements->get_pEntityPosition( ) + ( newVel * deltaTime );//add to positionflockElements->set_pEntityVelocity( newVel );flockElements->set_pEntityPosition( newPos );flock elements is a vector of entities but im only drawing one at the moment todebug this functionthe steer function from before hs been used on other movement and steering algorithms with good results so if you think its in there i doubt it, but if you wish to see it then by all means request itcheers   
  For some reason you clamp wander theta to be between -0.95 and 0.95.. Assuming that sin and cos expect radians this is significantly less than a full circle.Second, you are computing the point on the circle in world space rather than object space. I believe the the angle should be in object space so that, for example, a constant wander angle of -PI would lead the actor in a circle counter clockwise, and a constant wander angle of PI would lead them in a clockwise circle. If theta angle is zero, the actor should proceed straight ahead, which ever direction it may be facing. The second issue wouldn't be an issue if the first one didnt exist, and vs versa. So fix at least one of those problems and you should be good.   ;  cheers bzroom, i changed the theta too PI and he does now indeed wander up a full circle, the problem stems from the fact that i got the code elsewhere i kind of just plugged it in expecting it to work straight away, in fact they use values of 0.25f as the theta and they get a good range of wandering. Im not sure why   ;  I assume this is because their wandering circle is in object space, where zero theta means "go straight" a small negative means left, and a small positive means right. Since you are computing this in world space, if you stay near zero you will only allow the actor to move in approximately one direction.You can multiply the cosine factor by the "facing" vector, and multiply the sine factor by a vector perpindicular to this. Add them together to compute the circle point. so:What you have:vec circlePoint = vec( r*cos(t), 0, r*sin(t) );What you should have:vec circlePoint = facingVec * r * cos(t) + sideVec * r * sin(t);Then if you kept theta near zero the actor would continue in his facing direction. Any small theta offset form zero will cause him to start driving in a circle.   