Custom Character Controller Collision Problems

Hello! :smiley:

I am currently working on a character controller for a game I’m working on and due to the way I’ve scripted it, I have had to script the interaction between the player and obstacles myself. After a lot of work, I have managed to get it working! You can see this below:

Due to the features of this game, I would like for the player to be able to walk at an angle, like walking on a wall, but in this case I am going to use it to allow the player to walk around a planet with gravity.

The problem I am having is that when I flip the whole setup on it’s side, the calculations I am using to find which direction the player should move relative to the wall no longer work and the player stops when they reach the wall!

Please ignore the graphical glitch in the video above.

Below is a snippet of the code which I have edited to show only important information:

while wait() do
	movement = root.CFrame *, 0, speed)
	for i, hit in pairs(root.Parent.Hitbox:GetTouchingParts()) do
		if isFacingObject(root, hit) then -- Direction of movement is only changed if the player is facing the object.
			findClosestCorner(root, hit) -- findClosestCorner is a function which returns the closest corner of the part touched to the player. This information is required for the calculateFace function
			sideTouched = calculateFace(root, hit) -- calculateFace returns the face which the player is touching. E.g. 'front' or 'back'.
			x, y, z = hit.CFrame:ToObjectSpace(root.CFrame):ToOrientation()

			if sideTouched == "right" or sideTouched == "left" then
				y += math.rad(90)

			wallLookVector = (root.Parent.Hitbox.CFrame * CFrame.Angles(y, 0, 0)).LookVector -- Calculates look vector of wall
			wallForce = (, 0, 0), wallLookVector) * CFrame.Angles(-y, 0, 0)).LookVector -- Converts look vector of wall to have primary axis in direction that player is moving in.

			movement = root.CFrame +, speed, speed) * - root.CFrame.LookVector.X, 0, wallForce.Z - root.CFrame.LookVector.Z)
	root.CFrame = movement

Keep in mind that this script does not contain code for the player interaction, E.g. keyboard. This entire script was just to figure out the idea before I implement it into my character controller.

I realise that this is quite a complicated problem but I wondered if there was anybody that could shed some light on the solution!

Any help would be much appreciated! :grin: