Bodies Size

General discussion about the R.U.B.E editor
Post Reply
aqeel-raza
Posts: 4
Joined: Mon Mar 10, 2014 9:28 am

Bodies Size

Post by aqeel-raza »

Hi,
How can I set the width and height of bodies in R.U.B.E?
for example I want to set the height of 1.5 for a square how can i do?
sorry i am noob to R.U.B.E :P
Thanks
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Bodies Size

Post by iforce2d »

It sounds like you have not watched the video tutorials or read much help documentation.

You can find the video tutorials here: https://www.youtube.com/watch?v=2gb63dUzA-E
See the video description for links to the whole series.

Please also take a look at the "Getting started" mini-example in the built-in help, which covers a small sample of typical manipulation. After that, the topics under "Editing items" in the built-in help would also be a good place to read through.
aqeel-raza
Posts: 4
Joined: Mon Mar 10, 2014 9:28 am

Re: Bodies Size

Post by aqeel-raza »

Thanks
bvargish
Posts: 26
Joined: Fri Oct 02, 2015 4:17 pm

Re: Bodies Size

Post by bvargish »

Did you ever figure this out? I'm not finding an obvious way to do this in the help or the videos. Maybe I'm looking in the wrong spots. I need to enter in precise widths and height manually. Scaling with the GUI will not work for me.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Bodies Size

Post by iforce2d »

Bodies don't have any height or width of their own, they have fixtures.
Fixtures have vertices (for polygon/line/loop) or a radius (for circles).
It's the location of the vertices (or the radius of the circle) that define what we might commonly think of as the 'width' etc of a fixture. Note that bodies can have multiple fixtures so the overall 'width' or 'height' of a body would be the total of all its fixtures.

I think what's needed in this case is to manually position the vertices of a fixture. You can do this by selecting the vertices (in vertex edit mode) and entering a value for either the body coordinate or world coordinate. This is a bit tedious. If creating a new shape, you can start by doing 'Add a square fixture' which will give a 1x1 square, and then scale (restricted to X or Y axis if necessary) to make it 2x3 or whatever you need. This is all very well if the result you want is a nice factor to scale by, but not so easy if you want to set the sizes to more arbitrary values.

You could try this script which might make things easier. You need to select the fixture you'll be dealing with before running it. It will query you for the width and height, and then set the vertices as appropriate. It assumes the fixture is already set to be a polygon type.

Code: Select all

fixture f = sf()[0];
float width = queryNumericValue("Width:",1);
float height = queryNumericValue("Height:",1);
float w = width / 2;
float h = height / 2;
vec2[] verts;
verts.insertLast( mv(-w,-h) );
verts.insertLast( mv( w,-h) );
verts.insertLast( mv( w, h) );
verts.insertLast( mv(-w, h) );
f.setVertices( verts );
bvargish
Posts: 26
Joined: Fri Oct 02, 2015 4:17 pm

Re: Bodies Size

Post by bvargish »

Thanks so much for the insight and the script! I was thinking in bed last night about modifying the vertices, so I was going down the right path :) This whole thing has been a bit hard to wrap my head around since I'm so used to working in pixels rather than meters/units and I created my Flash game using pixel based World Construction Kit, but I'm getting there.

By taking the pixel coordinates of my original build and converting to units based on a pixel-to-meter ratio (Phaser uses 50 by default so I plan to go with that) I should be able to clone what I originally created. I'm thinking that this would result in a more accurate conversion than taking a screen grab and tracing everything. I'll likely still have to do some tweaking, but hopefully not as much as I had to do when I first built my game.

Once my levels are built, my plan is to scale all of the elements up as a group so I can make my game larger. I suppose another option might be to change the pixel-to-meter ratio to accomplish that, though I'm guessing Phaser is using 50 for a reason.

UPDATE: Per your cautionary headache saving email I will not edit the physics scale in R.U.B.E. and mess things up. I will adjust the pixels to meter ratio in Phaser using game.physics.box2d.setPTMRatio(55) to enlarge the world.
Last edited by bvargish on Wed Oct 07, 2015 6:01 pm, edited 1 time in total.
bvargish
Posts: 26
Joined: Fri Oct 02, 2015 4:17 pm

Re: Bodies Size

Post by bvargish »

The script works great! I updated your code so I can enter in the original pixel values and it will translate to meters for me :)

Code: Select all

float ppm = 50;
float w = width / ppm / 2;
float h = height / ppm / 2;
Will probably do the same to place and rotate my objects.
Post Reply