Move Entity "Towards" Position

Hello once again ^.^

I’ve almost got my NextBot NPC fully functional but need to tweak it’s movement behavior a tad.

Currently they move at random all over the map, Previously I had them moving directly towards a target.
I would like to combine both of these actions into one!



					self.TargetPos = MyPos + Vector( math.random( -1, 1 ), math.random( -1, 1 ), 0 ) * (self.FindRadius)

That finds a random position within a few hundered units away from the current position

How would I combine that to move towards, say, Vector(0,0,0), but not in a straight line, anywhere from a 90 degree angle from the current position towards Vector(0,0,0)?

Anyone know how I could pick a random position from my current position?
Not trying to pick one in a full 360 degree radius from the current position but more like 120 degrees where the center of this arc is pointed towards another position on the map?

Heres a pic to explain what I need

Red Square = Current Position
Black Square = Goal Position
Green Arc = Possible Positions To Choose From

Pointing the Green Arc towards the Black Square will eventually get the Red Square to the Black Square but he won’t go straight for it. More of a ‘controlled random movement’

[lua]local pos, radius, target, spreadangle – assume you have all this defined

local ang = (target - pos):Angle() – get the angle between your pos and target pos
ang:RotateAroundAxis(ang:Right(), math.random(0, spreadangle)) – rotate the angle by a random factor
ang:RotateAroundAxis(ang:Up(), math.random(0, spreadangle)) – ditto

local randompos = pos + ang:Forward()*radius – get the random pos [/lua]

That’s a little snippet of code I’ve thrown up right now, should do the trick.

math.random(-spreadangle, spreadangle) and yeah. Might want to not randomize pitch though (Right).

Whoopsie, my bad.