playMaker

Author Topic: Trying to constrain Player Character within a space that rotates  (Read 256 times)

JoeGameDev

  • Playmaker Newbie
  • *
  • Posts: 15
You guys helped so much with my last problem I thought I’d try again with my newest issue! Lol.

So my game takes place on a 3D cube from a 2D perspective. The character moves along one side of the cube at a time. The player can rotate the cube at 90 degree (actually rotating the camera, not the cube) increments, dragging the character with it. After you helped me figure out how to rotate the camera, I made the character child of the camera so they would rotate together. Works like a charm.

My new problem is this: I need the character constrained within the cube. As it is now, the character flies off the screen when I swipe far enough. I’m using LeanTouch + for touch controls, which work great, but the constraint options don’t seem to serve my purposes. For example, ConstrainToBox is great if I want to keep the character limited to just one face of the cube. But the key mechanic of my game is that the character moves along all four faces.

I tried another technique I found browsing this forum, basically a Get Position and Float Clamp/Set Position, but that breaks when I turn the cube, saying there’s an infinite loop. Which is weird because the X position doesn’t seem to change for the character when I turn the camera.

Any ideas how to constrain the character within the confines of the cube while also allowing the character to rotate with the camera?