Box2D Forums

It is currently Mon May 20, 2013 11:16 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Nov 18, 2011 2:04 pm 
Offline

Joined: Fri Oct 07, 2011 9:39 am
Posts: 21
Hello, I'm trying to find best possible way to move my Kinematic bodies with fixed speed.

With setLinearVelocity it works fine, but changing values, in fact does nothing (Doesn't change speed)

Also I noticed, with this way, on some devices (those better, with 2 CPU's for example) ... objects are moving much faster in compare to different devices :( (Which is really bad, for the same game'play obviously)

So I will be really grateful for some help in this subject, thank you for help!


Top
 Profile  
 
PostPosted: Sat Nov 19, 2011 2:08 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
If SetLinearVelocity works once, it should always work. You mean for example, setting a velocity of (5,0) will work and then setting it to (-5,0) does not work? What kind of values are you using? If you are using pixels as units you may be giving values above the maximum speed for a body to move.

About timing, if your game loop simply runs as fast as it can then a faster CPU will obviously get things done quicker. To keep it regular across different hardware you can use a timer, eg. checking that at least 1/60 second has passed before drawing the next frame will make it run at (roughly) 60 fps.


Top
 Profile  
 
PostPosted: Sat Nov 19, 2011 2:22 am 
Offline

Joined: Fri Oct 07, 2011 9:39 am
Posts: 21
Using values like 1 or -1 works (changing direction of the movement) but for example with value 1 or -1, speed is the same with any different value like for example 10 or -10 and so on.

Thanks for answer.


Top
 Profile  
 
PostPosted: Sat Nov 19, 2011 4:10 am 
Offline

Joined: Mon Jun 08, 2009 12:21 pm
Posts: 353
Linear velocity questions:
There is a maximum object speed for the engine, it's around 200, check the settings
It definitely sets the speed, you might have to make sure you're applying it outside of the engine's step call (so it's not in any contact listeners)

Speed/cpu:
The engine runs however fast you call it. You should be using a constant timestep as well, having a variable timestep is not recommended and causes big differences between machines.


Top
 Profile  
 
PostPosted: Sun Nov 27, 2011 1:05 am 
Offline

Joined: Fri Oct 07, 2011 9:39 am
Posts: 21
No idea why, but instead of:

setLinearVelocity(-5, 0)

its moving faster with

setLinearVelocity(-1 * 5, 0);

and so on, what ever, most important is it works, thanks for help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: psbot [Picsearch] and 0 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