Is it possible to constrain the physics of an object to only move in 2D? For instance in a 2.5D puzzle game, where you’re looking at the scene from a side and only want to 3D objects to move in 2D? Similarly to one of those contraption games, like Crazy Machines. I tried to add Physics Constraints to somehow achieve this, but I can’t get it to work. I thought I would be able to disable motion in Y direction, by adding a constraint that fixed the object’s distance to a static object along the Y axis. Maybe I’m doing something wrong. Can this be achieved with the built in physics engine, or would I have to integrate something like Chipmunk or Box2D?
http://maturegamerpodcast.com/wp-content/uploads/2014/02/Crazy-01-large.jpg
Hi Bajee,
Could you post the setup you tried with constraints and how it was failing?
Cheers,
Michael Noland
Hi Michael,
I interpreted your reply as “It’s possible and you probably messed up something”
So I recreated my experiment, tried lots of different settings and finally got it to work.
I still have a follow up question though. Is this kind of constraining “secure” or can it be violated in extreme cases or because of lags? I don’t want my objects to fall out of the level (move in X direction), towards the camera in any case. With a simple 2D physics engine, I would only ever change the Y and Z location and only rotate around X, so this could never happen.
Currently I have a movable SM actor with physics enabled, a static hidden “hook” actor and a physics constraint connecting them with these settings:
[table]
Linear XMotion
Locked
Linear YMotion
Free
Linear ZMotion
Free
Angular Swing 1Motion
Locked
Angular Swing 2Motion
Locked
Angular Twist Motion
Free
It also works if I don’t specify a second actor for the constraint. I assume it will constrain to the world origin in that case? I couldn’t find any info on that in the documentation.
Thanks!