# Follow behavior with randomization factor

I'm trying to make enemy follow player as in picture below, the code below is code for following player with steering behavior ( i'm not sure it steering works tho but it does follow player ), how would i code something like in the picture below to make the following more randomized but still going in direction of where player is.

Vector2f velocity,steering,desiredVel;
velocity = new Vector2f(player.getX() - getX(), player.getY() - getY());
velocity.normalise();
velocity.scale( maxVelocity);

// unsure what to do with random numbers yet
Random rand = new Random();
int randy = (rand.nextInt(101) -50);
int randx = (rand.nextInt(101)-50);

desiredVel = new Vector2f(player.getX() - getX() +randx, player.getY() - getY() +randy);
desiredVel.normalise();
desiredVel.scale( maxVelocity);

steering = desiredVel.sub(velocity);

steering = truncate(steering,maxForce);

steering.scale(1 / mass);

this.velocity = velocity; This is a simple mixing of two different steering behaviors. Following and wandering.  You can find information about implementing both in this GDC paper from '99.

Start with implementing both independently. Then apply both at the same time, with a blending factor. You'll have to modify the blending value depending on how much you want to wander vs how direct you want the steering to be.

If you want the regular pauses, you can add a random duration for the path following to run and another random duration for it to pause.

• in the first image , the first line it says quarry is that a typo? Apr 28 '13 at 18:23
• The quarry is the target.
– House
Apr 28 '13 at 18:31