Hello,
I've been breaking several things from the sample loaders in an effort to try to control a specific body from a RUBE scene. For example, the truck from the *"images" sample loader. Any advice would be greatly appreciated.
*Cocos2D Sample Loader
Thanks!
Using the Accelerometer with a specific body from RUBE Scene
-
- Posts: 22
- Joined: Tue Sep 10, 2013 3:59 am
Using the Accelerometer with a specific body from RUBE Scene
Last edited by Phantom Ppepper on Sun Nov 10, 2013 12:17 am, edited 1 time in total.
-
- Posts: 22
- Joined: Tue Sep 10, 2013 3:59 am
Re: Using the Accelerometer with a specific body from RUBE S
Actually, to be more specific to what I am trying to do, how would I control a "ball" from a top down view with the accelerometer?
Re: Using the Accelerometer with a specific body from RUBE S
Near the end of this video (about 25:00) is an example of finding a joint in the scene and controlling it:
http://www.youtube.com/watch?v=0UsKnXuZ2nQ
To control a ball in a top-down view would be very similar - find the ball body and apply a force to it.
http://www.youtube.com/watch?v=0UsKnXuZ2nQ
To control a ball in a top-down view would be very similar - find the ball body and apply a force to it.
-
- Posts: 22
- Joined: Tue Sep 10, 2013 3:59 am
Re: Using the Accelerometer with a specific body from RUBE S

After applying the same practices from the video, I still cannot seem to control my body with the accelerometer. To verify, acceleromter is enabled, and I am using the
Code: Select all
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
Code: Select all
-(void)afterLoadProcessing:(class b2dJson *)json
{
[super afterLoadProcessing:json];
Has anyone succesfully used the accelerometer with one of the sample loaders? (iphone cocos2d sample loader, latest update). Thanks in advance for any advice.
Re: Using the Accelerometer with a specific body from RUBE S
What are the values you are giving to ApplyForce? Are they large enough? The accelerometer gives you values between -1 and 1 so you would have to scale them up or down to suit the mass of whatever you are trying to move.
To move a ball as if it was rolling on a table in a top-down view, I think you would want to use the x and y components.
The b2World class has a SetGravity function that should change the gravity.
I wonder if you have seen this, it looks helpful: http://www.merowing.info/2013/04/learn- ... v-level-0/
You could use ApplyForce to move the body, or change the gravity, but I don't think it makes sense to do both.
To move a ball as if it was rolling on a table in a top-down view, I think you would want to use the x and y components.
The b2World class has a SetGravity function that should change the gravity.
I wonder if you have seen this, it looks helpful: http://www.merowing.info/2013/04/learn- ... v-level-0/
You could use ApplyForce to move the body, or change the gravity, but I don't think it makes sense to do both.
-
- Posts: 22
- Joined: Tue Sep 10, 2013 3:59 am
Re: Using the Accelerometer with a specific body from RUBE S
ahh! I am anxious to get home and try another go at this. My current force values are
I had previously tried using "applyforce" and probably still will, now that I have your link! Thanks!
In my other searches, this was the only thing that I hadn't seen:
On the website, he is using chipmunk and references "LevelViewController viewDidAppear" method. Would this be the tick method in Box2D?
I'm anxious to see if that does it.
Code: Select all
m_player->SetLinearVelocity(b2Vec2(acceleration.x *20,m_player->GetLinearVelocity().y*20));
In my other searches, this was the only thing that I hadn't seen:
Code: Select all
UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
accelerometer.updateInterval = 1.0f / 30.0f;
accelerometer.delegate = self;
I'm anxious to see if that does it.
Re: Using the Accelerometer with a specific body from RUBE S
I'm pretty sure SetLinearVelocity is not the way to go with this. Applying forces is a much better representation of gravity changing. Probably something like:
I think the viewDidAppear is just something that gets called once at the beginning. For cocos2d I suppose it would be analogous to applicationDidFinishLaunching.
Code: Select all
float gravMod = 10;
b2Vec2 direction(acceleration.x, acceleration.y);
m_player->ApplyForce( gravMod * direction, m_player->GetWorldCenter() );
-
- Posts: 22
- Joined: Tue Sep 10, 2013 3:59 am
Re: Using the Accelerometer with a specific body from RUBE S
Ahh I see, you are correct. Apply force is MUCH better
thanks!!
