public TV_2DVECTOR Wander()
{
int Sign = m_Random.Next(0, 1);
float Number = (float)m_Random.NextDouble();
if (Sign == 0)
Number = -Number;
m_Settings.WanderTarget += new TV_2DVECTOR(Number * m_Settings.WanderJitter, Number * m_Settings.WanderJitter);
m_Math.TVVec2Normalize(ref m_Settings.WanderTarget, m_Settings.WanderTarget);
m_Settings.WanderTarget *= m_Settings.WanderRadius;
TV_2DVECTOR TargetLocal = m_Settings.WanderTarget + new TV_2DVECTOR(m_Settings.WanderDistance, 0);
return TargetLocal - m_Position;
}
Steering Behaviors: Wandering problem
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play
"Reducing the world to mathematical equations!"
m_Settings.WanderTarget += new TV_2DVECTOR(Number * m_Settings.WanderJitter, Number * m_Settings.WanderJitter);
According to this line and the ones following it, it seems to be that you will always jiiter between either (WanderRadius, WanderRadius) or (-WanderRadius, -WanderRadius).
TV_2DVECTOR TargetLocal = m_Settings.WanderTarget + new TV_2DVECTOR(m_Settings.WanderDistance, 0);
I can't make sense of this line. Why are you adding an offset to what I assume is the x coordinate?
return TargetLocal - m_Position;
so what is this method actually supposed to return? That isnt clear, and is probably your main problem.
You normalize WanderTarget, which means that it will be at exactly 1 unit from origin, you then scale it using a radius and add an offset to its X value (as Steadtler pointed out).
If you read your return value line, you're substracting a LOCAL offset with a WORLD position. Seems like you should only be returning TargetLocal.
Edit: Also you're normalizing a vector that could be of length 0 if Number or WanderJitter is 0...
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play
"Reducing the world to mathematical equations!"