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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:10:45+00:00 2026-06-15T06:10:45+00:00

I’m struggling to learn and understand box2d. Here is my problem: I’m trying to

  • 0

I’m struggling to learn and understand box2d. Here is my problem:

I’m trying to make a simple car, the car body looks like this for now:

enter image description here

Now I’m trying to add a wheel, I create the wheel body and I assume I’ll link the wheel to the car body using a b2RevolutionJoint.

Until I get to that part I just want to be able to position the wheel in its place, so in relation to the bodyCar Body. How do I do this correctly?

What I’ve seen online is something like this:

bodyDef2.position.Set(axle2->GetWorldCenter().x + 1.3*cos(-M_PI/3), axle2->GetWorldCenter().y + 0.3*sin(-M_PI/3));

However, I don’t understand the cos and sin parts of that expression.

What I’m trying to do is this:

backWheelDef.position = b2Vec2(carBody->GetWorldCenter().x - 20.0/PTM_RATIO,carBody->GetWorldCenter().y);

Since my carBody vertices definition looks like this:

b2Vec2 vertices[] = {
        b2Vec2(100.0/PTM_RATIO,15.0/PTM_RATIO),
        b2Vec2(100.0/PTM_RATIO,30.0/PTM_RATIO),
        b2Vec2(50.0/PTM_RATIO,65.0/PTM_RATIO),
        b2Vec2(20.0/PTM_RATIO,65.0/PTM_RATIO),
        b2Vec2(0.0/PTM_RATIO,45.0/PTM_RATIO),
        b2Vec2(0.0/PTM_RATIO,15.0/PTM_RATIO)

    };

The result of the above way of positioning the wheel looks somehow correct (see below screenshot) but if you look at the above numbers it doesn’t make much sense.

Since the carBody width is 100.0/PTM_RATIO I assume the GetWorldCenter().x would return a value equal to 50.0/PTM_RATIO.

So the wheel position would be after calculation at 30.0/PTM_RATIO, right?

Well, if you look at the result below the wheel x positioning seems to be at 20.0/PTM_RATIO.

enter image description here

Can someone please explain how things work with positioning bodies in relation to other bodies works in Box2D? Once I’m clear with these kind of things I’ll move on to linking them using joints

Thanks a bunch!

LATER EDIT BASED ON iforce2d ANSWER:

Thank you iforce2d for answering and thank you for all the good insight you provide in the box2d world. What you’re saying is perfectly true but this wasn’t my question.

Once I’ve figured out that GetWorldCenter returns the center of gravity and GetPosition returns the position origin of the object it was easy to place my wheel exactly where I needed it to be in relationship to the carBody. Even though I still got the behaviour of it appearing under the body I knew this would be fixed once I add joints into equation.

Now I have another question that somehow relates to this positioning problem. Take a look at the image below:

enter image description here

Is this the right way my joints should look once I set their anchor points as below? I’m a little confused by them going from origin instead of them going from anchorPointA to anchorPointB

Thanks again!

  • 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-15T06:10:46+00:00Added an answer on June 15, 2026 at 6:10 am

    You are placing the wheel inside the car body to begin with, so in the first two or three time steps the two bodies will move to correct the overlap. It probably happens so fast that you don’t see it, but the tell-tale signs are there, namely the wheel being positioned exactly at the edge of the car, and the car body being rotated a tiny bit.

    If you pause the simulation (just don’t call Step) you should see the bodies where you expect to see them.

    Once you add the joint, the default behavior is for the two joined bodies not to collide with each other, so you wont see this problem.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
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 would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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

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.