I need help with using CFrame angles for a hoverboard project!

Hey, so I’m having difficulty trying to solve something, you see I am basically making a hoverboard and I’ve got almost everything working perfectly, it hovers, it moves, but there’s one tiny problem.
https://streamable.com/rptd3q
It doesn’t angle on objects properly!

At first I thought that just using the surface normals of my hovering raycast would suffice, but unfortunately it doesn’t since it screws up the rotation bit of the board on it’s Y axis when moving around, It seems that I need to essentially only take in the X and Z axis’ of a surface normal for this to work.

Here’s the essential code I’m using for this…

		if onboard == true then
			local movement = char.Humanoid.MoveDirection
			local pushfactor = 4
			local pushfactordivider = -pushfactor
			local wantedheight = 3.5
			local dampening = 1
			if char.Humanoid.MoveDirection.X ~= 0 or char.Humanoid.MoveDirection.Z ~= 0 then
				rotation = -math.atan2(char.Humanoid.MoveDirection.X,char.Humanoid.MoveDirection.Z) * 57.4 - math.pi / 2
			end
			rot.MaxTorque = Vector3.new(4000,4000,4000)
			rot.P = 4000	
			local rayparams = RaycastParams.new()
			rayparams.FilterType = Enum.RaycastFilterType.Blacklist
			rayparams.FilterDescendantsInstances = {char,first,first3,first2}
			
			first.Position = char.HumanoidRootPart.CFrame.p
			
			first2.Position = char.HumanoidRootPart.CFrame.p + -char.HumanoidRootPart.CFrame.UpVector * 11
			local ray = game.Workspace:Raycast(char.HumanoidRootPart.Position + char.HumanoidRootPart.CFrame.LookVector * 2.5,-char.HumanoidRootPart.CFrame.UpVector * 11,rayparams)
			local actualpushfactor = 0
			local rot7 = 0
			local rot6 = 0
			local x, y, z = 0,0,0
			if ray then
				local raypos = ray.Position
				first3.Position = ray.Position
				local boardpos = char.HumanoidRootPart.CFrame.p + Vector3.new(0,-1,0)
				local check = (boardpos.Y - raypos.Y)
				local percentage = math.clamp(math.abs(check / pushfactor),0,1)
				print(math.abs(percentage))
				if check > wantedheight then
					percentage = percentage
				else
					percentage = percentage
				end
				rot7 = ray.Normal
				x, y, z = rot7.X , rot7.Y ,rot7.Z
				print(x.."| "..y.." |"..z)
				local reduction = pushfactor * percentage
				actualpushfactor = pushfactor - reduction
			end
			
			
			if rotation ~= 0 then
				rot.CFrame = CFrame.new(char.HumanoidRootPart.Position) * CFrame.Angles(z,math.rad(-rotation + 180),0)
			end
			
			
			mover.MaxForce = Vector3.new(9999,9999,9999)
			local thevel = char.HumanoidRootPart.CFrame:VectorToObjectSpace(Vector3.new(0,0,-8))
			if movement ~= Vector3.new(0,0,0) and ray then
				if char.HumanoidRootPart.Velocity.Y > 0 then
					mover.Velocity = Vector3.new(char.HumanoidRootPart.Velocity.X * 0.9,char.HumanoidRootPart.Velocity.Y - 2,char.HumanoidRootPart.Velocity.Z * 0.9) - Vector3.new(thevel.X,thevel.Y,-thevel.Z) + char.HumanoidRootPart.CFrame:VectorToWorldSpace(Vector3.new(0,actualpushfactor,0))
				else
					mover.Velocity = Vector3.new(char.HumanoidRootPart.Velocity.X * 0.9,char.HumanoidRootPart.Velocity.Y * 0.9 - 2,char.HumanoidRootPart.Velocity.Z * 0.9) - Vector3.new(thevel.X,thevel.Y,-thevel.Z) + char.HumanoidRootPart.CFrame:VectorToWorldSpace(Vector3.new(0,actualpushfactor,0))
				end	
			else
				if movement ~= Vector3.new(0,0,0) then
					mover.Velocity = Vector3.new(char.HumanoidRootPart.Velocity.X * 0.9,char.HumanoidRootPart.Velocity.Y - 2 ,char.HumanoidRootPart.Velocity.Z * 0.9) - Vector3.new(thevel.X,thevel.Y,-thevel.Z)
				else
					mover.Velocity = Vector3.new(char.HumanoidRootPart.Velocity.X * 0.9,char.HumanoidRootPart.Velocity.Y - 2 ,char.HumanoidRootPart.Velocity.Z * 0.9)
				end	
				if ray then
					if char.HumanoidRootPart.Velocity.Y > 0 then
						mover.Velocity = Vector3.new(char.HumanoidRootPart.Velocity.X * 0.9,char.HumanoidRootPart.Velocity.Y - 2,char.HumanoidRootPart.Velocity.Z * 0.9) + char.HumanoidRootPart.CFrame:VectorToWorldSpace(Vector3.new(0,actualpushfactor,0))
					else
						mover.Velocity = Vector3.new(char.HumanoidRootPart.Velocity.X * 0.9,char.HumanoidRootPart.Velocity.Y * 0.9- 2 ,char.HumanoidRootPart.Velocity.Z * 0.9) + char.HumanoidRootPart.CFrame:VectorToWorldSpace(Vector3.new(0,actualpushfactor,0))
					end	
				end
			end
			
			char.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
			char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp,false)
			char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running,false)
			char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics,false)
			char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics,false)
			char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing,false)
			char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics,false)
			char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding,false)
			char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown,false)
			
		end

If anyone has any info that can help me understand this better I’d greatly appreciate it!

5 Likes

Does the video work since for me it won’t play??

I think @Starfythewat already solved it in a different post, but yeah I can confirm the video is not working.