# Physics. Constraining to one axis?

Discussion and feedback on Construct 2

### » Sun Nov 11, 2012 8:09 pm

Is there a way to do this? Say that I want an object to have physics in along the x-axis, but always have the same y-axis position - as if it were running on a rail.

I can't find a way - and hacking it through setting Y every frame has nasty results.
B
11
S
4
G
3
Posts: 70
Reputation: 3,076

### » Sun Nov 11, 2012 8:34 pm

A curious conundrum! I wonder how this could be done...
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,739

### » Mon Nov 12, 2012 12:24 pm

I wonder if it is possible to expose an expression like gravity direction from the official plugin?
B
7
S
1
Posts: 38
Reputation: 833

### » Mon Nov 12, 2012 2:47 pm

Could we have an example of when this effect would be used?
B
67
S
26
G
11
Posts: 674
Reputation: 11,559

### » Mon Nov 12, 2012 8:50 pm

Sure. There are lots of possible examples.

Scales - where the more weight you put on an object caused it to move down.

Pistons - moving up and down under physics - but never moving to the left or right.

B
11
S
4
G
3
Posts: 70
Reputation: 3,076

### » Mon Nov 12, 2012 8:52 pm

The gravity direction doesn't help much. You can fake that by switching off gravity and applying the force yourself. But still other objects can knock it off the axis you want to constrain it to.
B
11
S
4
G
3
Posts: 70
Reputation: 3,076

### » Mon Nov 12, 2012 9:21 pm

What happens when you try and use something like "every tick set x position to 100" on a physics object?

would that restrict it vertically?
B
91
S
44
G
17
Posts: 1,012
Reputation: 18,562

### » Mon Nov 12, 2012 10:03 pm

You could ... create two non-movable sprites just behind and in front of your object in an axis ?!

Try that ...
B
43
S
18
G
17
Posts: 2,247
Reputation: 17,556

### » Mon Nov 12, 2012 10:35 pm

@justifun This I have tried. And the results are erratic. Seems to work well if the object is not colliding with anything. But if it's touching anything then it slows it down as if it had a massive coefficient of friction. Tried various workarounds - upshot is - it didn't work.
B
11
S
4
G
3
Posts: 70
Reputation: 3,076

### » Mon Nov 12, 2012 10:36 pm

@whiteclaws. Sort of tried this. Problem is that all other physics objects can also collide with those objects - hence they become not useful.
B
11
S
4
G
3
Posts: 70
Reputation: 3,076

Next