Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7045587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:32:55+00:00 2026-05-28T02:32:55+00:00

I have created enemies that chase the player around a game, but there is

  • 0

I have created enemies that chase the player around a game, but there is a problem. The enemies are too perfect and quickly converge on each other when they get close to the player. This is because they just move in the direction of the player each time the game updates.

I would like to introduce some randomness into the enemies, probably with the angle of motion. This is what I have so far (I haven’t optimized it as it’s not done yet, so I’m aware of the high overhead):

Angle = (float)Math.Atan2((HeroPosition - Position).Y, (HeroPosition - Position).X)// Positions are Vector2s
GlobalForce Propellant = new GlobalForce((float)Math.Cos(Angle) / 2, (float)Math.Sin(Angle) / 2);
ApplyForce(Propellant);

If I try to add a random number to the angle there are a couple of problems:

  1. They all get updated so quickly after each other that the seed time is the same for all of them

  2. The random number is so different on each update that the angle of the enemy jumps around erratically.

So what I want to know is: How do most games get around this problem? How should I make the enemies take different paths (without having access to the list of other enemies)?

EDIT:

This is the code I am using after the suggestions below for future passers by:

Angle = (float)Math.Atan2((HeroPosition - Position).Y, (HeroPosition - Position).X);
GlobalForce Propellant = new GlobalForce((float)Math.Cos(Angle) / 2, (float)Math.Sin(Angle) / 2);
ApplyForce(Propellant);

foreach (Enemy e in OtherEnemies)
{
    if (e != this)
    {
        if ((e.Position - Position).Length() < 64)
        {
            float angleBetween = MathHelper.TwoPi-(float)Math.Atan2((e.Position-Position).Y, (e.Position-Position).X);
            GlobalForce avoidance = new GlobalForce((float)Math.Cos(angleBetween)*2, (float)Math.Sin(angleBetween)*2);
            ApplyForce(avoidance);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:32:56+00:00Added an answer on May 28, 2026 at 2:32 am

    Most games get around this by having the enemies block each other, so that they don’t move onto the same space.

    This can be implemented as either a hard constraint (e.g. only one enemy is allowed in each square, no other enemies can move into an already occupied square) or a soft constraint (some hidden “force” that pushes enemies apart if they get too close to each other).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a dialog and got a problem that only part of the
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created some JQuery that will expand a div 'popup' on hover and
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a function that shows/hides different messages according to a combination of
Have created a custom navigation menu in wordpress that has some pages and some
I have created sample application that insert 12 rows in tableview.And inserted fine.When after
Have created an attribute property in TableView1.h and pushing that attributes value to another
I have created custom listview in that have list of textview & list of
I have created a console application in C# and there is main method (static)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.