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.
A curious conundrum! I wonder how this could be done...
I wonder if it is possible to expose an expression like gravity direction from the official plugin?
Could we have an example of when this effect would be used?
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.
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.
Develop games in your browser. Powerful, performant & highly capable.
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?
You could ... create two non-movable sprites just behind and in front of your object in an axis ?!
Try that ...
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.
— Sort of tried this. Problem is that all other physics objects can also collide with those objects - hence they become not useful.
Hmmm ... Really enigmatic ... Wait ...you could make a script that makes the object move behind or in-front depending on if the player is colliding with the fences ... You wouldn't need to make the fences physical ...
I don't quite understand what you mean
Can't you just set it as immovable, then programmatically update its position. That's what I do for floating platforms that move side to side.
thehen that means he doesn't get physics interactions.
This is an interesting challenge!
I must be the only one who thinks this doesn't make sense :/ Surely the point of implementing a physics behavior is so that objects react as realistically as possible (?!)
Having an option to constrain an aspect of the physics implementation would surely invalidate that.
My 2 cents.