# Box2D Forums

 It is currently Fri May 24, 2013 6:23 pm

 All times are UTC - 8 hours [ DST ]

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Posted: Mon May 21, 2012 9:40 am

Joined: Tue Apr 03, 2012 12:56 am
Posts: 7
Hello everybody,

The bottom line is an approach to rotating bodies without setting the transformation directly. This yields a "physically correct" method.

Now comes the point of my post... I would like to do the same for the position! Again, setting the transformation directly would not be a proper solution.

I am interested in two things. Maybe you can help?
1. moving a body to a given position instantaneously while maintaining physical correctness, and
2. moving a body to a given position gradualy, that is over time.

Cheers!

Top

 Posted: Mon May 21, 2012 5:38 pm

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
hi az
Is this to move a dynamic body to match a touch drag on iPhone etc? These links could be useful:
http://stackoverflow.com/questions/6170 ... tion-box2d
http://stackoverflow.com/questions/1922 ... tial-delay
I think the first one would give you a way do the 'gradually' part of your question as well, if you limit the maximum allowed speed.

Top

 Posted: Thu May 24, 2012 10:30 am

Joined: Tue Apr 03, 2012 12:56 am
Posts: 7
Thanks! That was very inspiring!

I am thinking about moving vehicles in a top-down scenario. Dragging with mouse/finger would be like a specialized case of that.

I have a very first result. Moving instantaneously works like a charm. Like this:
1. compute the difference vector of current position and goal position
2. multiply the distance vector with the frame rate
3. set the body's velocity to the resulting vector
4. set the body's velocity to zero after updating the physics system.

Step 3. ensures that the body is at the goal position after updating the physics system. I think I can define a speed maximum in step 3 to move more gradually. Should work too (not tested yet).

I think this solves my problem of instantaneous and gradual movement in a simple way.

Still I am interested in a more convincing method that yields a more realistic behavior (like real vehicles):
1. accelerate the body toward the goal position by applying force(s)
2. stop accelerating when a max-speed is reached
3. maintain speed for traversing most of the distance
4. reduce speed when close to goal
5. end up exactly at the goal position.

Accelerate - move - decelerate - be at goal position.

I should have a look at the joints now... In the meantime, does anyone of you have some more inspiriation? Would the mouse-joint help?

Cheers!

Top

 Posted: Sat May 26, 2012 6:10 am

Joined: Tue Apr 03, 2012 12:56 am
Posts: 7
A quick update. As expected, limiting the speed in the previous approach yields gradual movement. That is great.

Still I am looking for a more sophisticated solution and would be happy for any ideas and hints.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 4 posts ]

 All times are UTC - 8 hours [ DST ]

#### Who is online

Users browsing this forum: No registered users and 4 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 Search for: