Rotation of an object in the other side

General discussion about Box2D tutorials
Post Reply
FLYNSXCOOL
Posts: 25
Joined: Tue Sep 19, 2017 4:30 pm

Rotation of an object in the other side

Post by FLYNSXCOOL » Sat Oct 14, 2017 2:19 pm

I made two versions, one looks left the other looks right. Implemented a change of direction with the removal of the body and create a new one.
But on low laptop the game freezes at the moment of reversal.
How did you solved this problem? Maybe I need both versions of the body load while a second body to do not active? Then rearrange them and do not active the first body. Or to throw from World1 to World2 ?

FLYNSXCOOL
Posts: 25
Joined: Tue Sep 19, 2017 4:30 pm

Re: Rotation of an object in the other side

Post by FLYNSXCOOL » Sat Oct 14, 2017 3:57 pm

We Can take all the fixtures and replace them with other forms (shapes). Then take the connection information and recreate connections with recalculated data but will it be faster??? Loader Json makes this way of the files.

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: Rotation of an object in the other side

Post by iforce2d » Sun Oct 15, 2017 6:06 pm

What language are we talking about?
If you run your program as as debug build, you should be able to use the debugger to step into the code while it is running to see what it is doing.

Is it just a single body you want to flip? Replacing the whole body could be a lot of trouble because you need to manually set the velocity, rotation, angular velocity etc. Yes, it would be better to have two sets of fixtures, and switch between using different fixtures.

If you want to flip multiple bodies (and a structure of joints) then you will need to replace all the bodies. I don't think the result will look very good...

FLYNSXCOOL
Posts: 25
Joined: Tue Sep 19, 2017 4:30 pm

Re: Rotation of an object in the other side

Post by FLYNSXCOOL » Mon Oct 16, 2017 3:47 pm

Image

Code: Select all

b2dJson jsonR;
jsonR.readFromFile("obj/car_r.json", errorMsg, &World);
b2dJson jsonL;
jsonL.readFromFile("obj/car_l.json", errorMsg, &World);
manipulation with

Code: Select all

->SetActive(false); 
->SetActive(true);
and

Code: Select all


->GetPosition();
->GetAngle();
->GetLinearVelocity();

->SetTransform(pos, angle);			   
->SetLinearVelocity(speed); 
I think this choice is the fastest of all

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: Rotation of an object in the other side

Post by iforce2d » Tue Oct 17, 2017 9:46 am

Yes, I think that would work ok.

Post Reply