I’ve asked so many questions on DevForum I feel like people hate me
Anyway! On the project I’m working on the player moves on a 2D map with invisible walls at the sides, also, the player can look at the camera by pressing S
The problem is, when the player runs into a wall while looking at the camera, they start to slide and eventually go out of bounds
Like this!:
I’ve tried teleporting them back If they go too far away, but this is kinda displeasing fix, because the player SHOULDN’T be able to go out of bounds
Hey, im not sure if this will disturb anything thats currently in the game, but i suppose it would be possible if you place another invisible wall infront of the camera basically blocking the player from going out of bounds.
How about you try putting a BodyPosition inside of the character’s rootpart and then in a heartbeat loop set the BodyPosition’s Position to the characters position but the trick is to make that vector’s Z axis a static value of where your character is standing on the global Z before moving out of bounds
IN THEORY
This should work because BodyPosition will always try to make the position of whatever it’s parented too match it’s own Position
For example
local BodyPosition
local middleZAxisOfMap = 150
-- Would be in a heartbeat loop V
BodyPosition.Position = Vector3.new(root.Position.X, root.Position.Y, middleZAxisOfMap)
You almost were correct, if you mean creating the BodyPosition in a heartbeat loop obviously you dont wanna do that but if you want it to keep with the rootparts current position you need to set it in a loop, because if you set it just once and you try to move itll keep going back to the original positon you had set before; which isnt what @SharkRayMaster wants
Oh wait I think I see what you mean so only apply the max force on the axis the is left and right according to @SharkRayMaster 's game and keep the other axis MaxForces to 0, this way itll always try to keep the Z axis in line while the other ones wont be effected
BodyPosition is deprecated so youll have to get it from toolbox but, if you dont wanna use deprecated stuff thats understandable you can do iit with other physics constraints but it just wont be as straightforward as with a BodyPosition, but anyway thats pretty much all you need too know to get it to work
Honestly I’m amazed I didn’t even know this object existed, I messed around with it abit and couldn’t get it to work but it was very interesting regardless