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

  • Home
  • SEARCH
  • 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 7988909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:35:42+00:00 2026-06-04T12:35:42+00:00

Imagine a segmented creature such as a centipede. With control of the head segment,

  • 0

Imagine a segmented creature such as a centipede. With control of the head segment, the body segments are attached to the previous body segment by a point.

As the head moves (in the 8 cardinal/inter-cardinal directions for now) a point moves in relation to its rotation.

public static Vector2 RotatePoint(Vector2 pointToRotate, Vector2 centerOfRotation, float angleOfRotation)
{
    Matrix rotationMatrix = Matrix.CreateRotationZ(angleOfRotation);
    return Vector2.Transform(pointToRotate - centerOfRotation, rotationMatrix);
}

Was going to post a diagram here but you know…

 center(2)      point(2)                      center(1)    point(1)



                                                     point(1)                    

                point(2)    ^                                        |
                           / \                                       |
                            |                                        |
 center(2)                                           center(1)      \ /
                                                                     V

I have thought of using a rectangle property/field for the base sprite,

private Rectangle bounds = new Rectangle(-16, 16, 32, 32);

and checking that a predefined point within the body segment remains within the head sprite’s bounds.
Though I am currently doing:

     private static void handleInput(GameTime gameTime)
    {
        Vector2 moveAngle = Vector2.Zero;

        moveAngle += handleKeyboardMovement(Keyboard.GetState()); // basic movement, combined to produce 8 angles
                                                                  // of movement

        if (moveAngle != Vector2.Zero)
        {
            moveAngle.Normalize();
            baseAngle = moveAngle;
        }

        BaseSprite.RotateTo(baseAngle);

        BaseSprite.LeftAnchor = RotatePoint(BaseSprite.LeftAnchor,
 BaseSprite.RelativeCenter, BaseSprite.Rotation); // call RotatePoint method

        BaseSprite.LeftRect = new Rectangle((int)BaseSprite.LeftAnchor.X - 1,
 (int)BaseSprite.LeftAnchor.Y - 1, 2, 2); 
 // All segments use a field/property that is a point which is suppose to rotate around the center
        // point of the sprite (left point is (-16,0) right is (16,0) initially
        // I then create a rectangle derived from that point to make use of the .Intersets method of the
        // Rectangle class

        BodySegmentOne.RightRect = BaseSprite.LeftRect; // make sure segments are connected?

        BaseSprite.Velocity = moveAngle * wormSpeed;

        //BodySegmentOne.RightAnchor = BaseSprite.LeftAnchor;

        if (BodySegmentOne.RightRect.Intersects(BaseSprite.LeftRect)) // as long as there two rects occupy the 
        {                                                             // same space move segment with head

            BodySegmentOne.Velocity = BaseSprite.Velocity;
        }

    }

As it stands now, the segment moves with head but in a parallel fashion. I would like to get a more nuanced movement of the segment as it is being dragged by the head.

I understand that the coding of such movement will be much more involved than what I have here. Some hints or directions as to how I should look at this problem would be greatly appreciated.

  • 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-04T12:35:44+00:00Added an answer on June 4, 2026 at 12:35 pm

    I will describe what you need to do using a physics engine like Farseer but the same holds if you want to write your own physics engine.

    1. Create a Body for each articulated point of the centipede body.
    2. Create a Shape that encapsulates the outer shell that will be attached to each point.
    3. Attach the Body and Shape using a Fixture. This creates one link in your centipede.
    4. Attach multiple links using a SliderJoint.

    For example – assuming that the outer shell of each link is a circle, here’s how to create two links and join them together.

        Fixture fix1 = FixtureFactory.CreateCircle(_world, 0.5f, 1, new Vector2(-5, 5));
        fix1.Body.BodyType = BodyType.Dynamic;
    
        Fixture fix2 = FixtureFactory.CreateCircle(_world, 0.5f, 1, new Vector2(5, 5));
        fix2.Body.BodyType = BodyType.Dynamic;
    
        JointFactory.CreateSliderJoint(_world, fix1.Body, fix2.Body, Vector2.Zero, Vector2.Zero, 10, 15);
    

    Now applying a force on any of the bodies or collisions on the shapes will drag the second joint around – just like you want.

    This is all just stick physics – so you could implement your own if you REALLY wanted to. 😉

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

Sidebar

Related Questions

Imagine an HTML form and the jQuery library is loaded. I'd like it such
What is the largest set of seven-, fourteen-, or sixteen-segment LCD symbols such that
Imagine you have an entity that has some relations with other entities and you
Imagine you are developing a Java EE app using Hibernate and JBoss. You have
Imagine the following table (called TestTable ): id somedate somevalue -- -------- --------- 45
imagine if you will the following string: A Great Movie (1999) DVDRip.avi I am
Imagine an interface with a method to create objects of type Address . The
Imagine the scenario you have a listing page that is a concatenation of multiple
Imagine I have a table which stores a series of sparse vectors. A sparse
Imagine I have a method: void Method(bool parameter){ if(parameter){ // first case } else

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.