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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:57:19+00:00 2026-05-25T00:57:19+00:00

I have been trying to use a MouseJoint to move a piece wherever the

  • 0

I have been trying to use a MouseJoint to move a piece wherever the user touches. But the piece, being affected by the joint, behaves strangely, never reaching the point. This is the code (x and y are already converted to ‘physical’ units):

MouseJointDef mj_def;
MouseJoint mj = null;
Body mj_gbody;

public void move(float x, float y)
{
    if(mj == null)
    {
        BodyDef mgbd = new BodyDef();
        mj_gbody = wrld.createBody(mgbd);
        //
        mj_def = new MouseJointDef();
        mj_def.bodyA = mj_gbody;
        mj_def.bodyB = body;
        mj_def.collideConnected = true;
        mj_def.maxForce = 20.0f * body.getMass();
        //mj_def.target.set(x,y);

        mj = (MouseJoint)wrld.createJoint(mj_def);
        body.setAwake(true);
    }

    mj.setTarget(new Vector2(x, y));
}

I was looking for some way to establish the anchor point in the BodyB, as the ‘strange behaviour’ that I mentioned seems to make the body gravitate around the established point (an orbit twice the width of the object), as if the anchor point was outside of the body (hexagon shaped, btw). But I don’t see any way of doing so in libgdx.

Does anybody know what I am doing wrong? Thank you in advance!

  • 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-25T00:57:20+00:00Added an answer on May 25, 2026 at 12:57 am

    Well, MouseJoint was working properly, I just misunderstood how MouseJoint works.

    As it is clearly seen in the Box2d testbed, MouseJoint is used for dragging after selecting an object. Therefore, the anchor is assigned in the first target.set.

    As I wanted to move the center of the object to the place where the mouse was (or the user touched), a mj_def.target.set(body.getPosition().x + 2.0f, body.getPosition().y + 1.0f); (the object is 4.0f by 2.0f) in the initialization solved the problem. Also, it may be not the best Joint for my intentions (to move an specific object to one place in the screen).

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

Sidebar

Related Questions

I have been trying to use follow scroll to move dialog together with user
I have been trying to use the same HttpClient instance throughout different activities, but
I have been trying to use localstorage to store Jquery-min but I am unable
I have been trying to use code-first migrations, and had some limited success, but
I have been trying to use JQuery UI but cant seem to get any
I have been trying to use system(tar -jcvf archive_name.tar.bz2 $my_file) but I get an
I have been trying to use a .gif file from my resources, but I
I have been trying to use the class located here . But I have
I have been trying to use nextAll() and siblings() but those functions never return
I have been trying to use OleDbDataAdapter to update a DataTable but got confused

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.