I am making a sidescroller, where movement is predominantly along the Y and Z axis. However, when interacting with certain objects (for instance, when colliding with spherical or cylindrical objects), the character tends to get moved along any axis the engine deems fit, including the X axis. This is problematic, since it moves the character out of range of any objects the character can interact with.
Now I have tried constraining the player through the way I have found through the answerhub, but no luck so far. I have tried locking the translation in the bodyinstance of the main capsule component, I have tried setting up some constrains using the character movement component, but nothing I have found so far seems to work.
Does anyone know how I can permanently disable movement along the X axis and the X axis alone, for a player character?
Just found a solution to this problem in the Side Scroller template project in version UE 4.20.
Looks like the settings you want are in the Character Movement Component under “Planar Movement”:
Constrain to Plane: true
Snap to Plane at Start: (I’ve set this to true. Looks like it just ensures that position of the character on the locked axis is always set to 0 when it spawns)
Plane Constraint Axis Setting: (Whichever axis you want to lock, but I’ve set it to “Use Global Physics Setting”. I think this uses the value from the project settings: Engine->Physics->Simulation “Default Degrees Of Freedom”. Since I’ll want any future physics simulation to be locked to the same axis, this seems the best way to easily stay in sync with the settings.)
No idea why those settings aren’t set by default for the Side Scroller template project…
I realise it’s probably too late for this to help you now, but hopefully it will help others with the same problem (I found your question searching for the solution to this problem)
Just to update this thread: If you need to disable the constraint at runtime the function is called “Set Plane Constraint Enabled” and the get is called “Get Constraint to Plane”.
I don’t know why they’re called differently but I had to search through the source code to find the setter, so I hope to help someone who will find this post in the future before the actual solution (like I did)
An update for 5.3, I found that if you set the “True”, as mentioned by Jonwood, it works. When playing, I would pause and find that my characters kept going into the 3rd dimension. This stopped.