Separate position x and y coordinates in IDE

What would you like to see in future versions of the editor?
Post Reply
totebo
Posts: 5
Joined: Sat Jul 19, 2014 9:14 am

Separate position x and y coordinates in IDE

Post by totebo »

I often want to set bodies to a common x or y coordinate.

As an example, I would like to change the x position of five bodies to 0, and retain their current y position.

This is how it is achieved currently:

1. Select one of the five bodies
2. Select the "Position" textfield property
3. Select what's left of the comma and change it to the correct value
4. Goto 1 for the remaining four bodies

Separating x and y positions would reduce the workflow to:

1. Select all five bodies
2. Enter 0 in the x position textbox and press enter

This would also be useful for vertices.

Cheers,

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

Re: Separate position x and y coordinates in IDE

Post by iforce2d »

Here is a script to do that:

Code: Select all

float x = queryNumericValue("Enter value to align with");

body[] bs = sb();
for (uint i = 0; i < bs.length; i++) {
	body b = bs[i];
	b.setPos( x, b.pos.y );
}
This is doing it for the x coordinate, but I think you can see how to make a similar script to change the y coordinate.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Separate position x and y coordinates in IDE

Post by iforce2d »

For vertices, perhaps you could try:

1. hit C,C to enter a cursor position manually
2. in the action menu choose "Vertex" -> "Align X to cursor"
totebo
Posts: 5
Joined: Sat Jul 19, 2014 9:14 am

Re: Separate position x and y coordinates in IDE

Post by totebo »

Excellent! First time I use a Script and it works a charm.

Niclas
Post Reply