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 8517113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:36:43+00:00 2026-06-11T05:36:43+00:00

I’m trying to build a path system involving the use of paths with waypoints.

  • 0

I’m trying to build a path system involving the use of paths with waypoints. At the moment I’m trying to render the path to the screen. I’m getting some success.

But, I have a problem being, between these checkpoints I need to make “lines”. The logic is below.

    for (int i = 0; i < paths.Count; i++)
        {
            for (int j = 0; j < paths[i].wayPoints.Count; j++)
            {
                if ((j + 1) < paths[i].wayPoints.Count)
                {
                    Vector2 point1 = paths[i].wayPoints[j];
                    Vector2 point2 = paths[i].wayPoints[j + 1];
                    Vector2 origin = new Vector2();


                    float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
                    float length = Vector2.Distance(point1, point2);

                    //batch.Draw(tileTexture, new Rectangle((int)point1.X, (int)point1.Y, cellSize, cellSize), Color.White);

                    batch.Draw(tileTexture, new Vector2((int)point1.X, (int)point1.Y), null, Color.White,
                        angle, origin, new Vector2(length/40, 1),
                        SpriteEffects.None, 0);
                }
           }
      }

The problem I’m having is that I can’t get my enemies to follow this path. Dependent on the rotation, they can go on the wrong side of the path. e.g. they go one cll too far to the right when travelling towards the bottom of the screen but when going back up, they’re in the right cell, where the path is drawing. I had this working with a map and drawing using rectangles if that’s any help.

  • 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-06-11T05:36:44+00:00Added an answer on June 11, 2026 at 5:36 am

    Are you talking about pixel perfect accuracy? Yeah I’ve had this problem too, and it’s down how rotation works, it rotates everything around the corner of the pixel rather than the middle of a pixel.. so no pixel remains in the same spot after a rotation. I gave up experimenting because it’s a very small thing that I can fix when I’m ironing out all the little bugs when I’m done.

    Here’s what my game looks like:

    enter image description here

    You can see that they are 1 pixel off, I’ve just come to live with it as I’m only making a prototype anyway, and as I said, it’s a small nitpicky thing to fix and I chose to add more functionality instead!

    Basically, you need to have a dynamic origin based on the rotation, the exact angle ranges to get it looking correct is something you’ll just have to experiment with.

    I think, if I’m reading your path drawing code correctly, you can only support none-diagonal lines. It may be worth saying that it might be your line drawing that is causing the error and not your drawing of the objects that follow the path! Here’s the code I use to draw lines:

    public void DrawLine(SpriteBatch spriteBatch, Vector2 lineStart, Vector2 lineEnd)
    {
        Vector2 d = lineEnd - lineStart;
    
        float angle = (float)Math.Atan2(d.Y, d.X);
    
        float distance = d.Length() + 1;
    
        if (Math.Abs(angle - MathHelper.Pi) < 0.01 || 
            Math.Abs(angle + MathHelper.PiOver2) < 0.01)
        {
            distance--;
        }
    
        spriteBatch.Draw(ScreenManager.BlankTexture, 
            new Vector2(lineStart.X + 0.5f, lineStart.Y + 0.5f), 
            null, nodes[i].Item2, angle, new Vector2(0f, 0.5f),
            new Vector2(distance, level.GridLineThickness), 
            SpriteEffects.None, 0);
    }
    

    This works very well for me, nodes[i].Item2 is just a colour reference. As far as I can tell this works for all cases… but then again it works for all cases for my work, I’m sure you can tweak it for your needs, if you decide to use it.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.