Box2D Forums

It is currently Wed May 22, 2013 12:47 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon May 21, 2012 9:40 am 
Offline

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

recently I had some fun and good results with this article: http://www.iforce2d.net/b2dtut/rotate-to-angle

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
 Profile  
 
PostPosted: Mon May 21, 2012 5:38 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
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
 Profile  
 
PostPosted: Thu May 24, 2012 10:30 am 
Offline

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
 Profile  
 
PostPosted: Sat May 26, 2012 6:10 am 
Offline

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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot] and 4 guests


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

Search for:
Powered by phpBB® Forum Software © phpBB Group