My code welds a torso to the wall on touch
When a player presses 'W', the camera's lookVector and the torso's lookVector are used so the player can move along the wall so it looks like they are running on the wall.
Here's a snippet of the code-
if keys["w"] and character.welded1.Value == true then
torso.CFrame = CFrame.new(torso.Position,torso.Position+Vector3.new(cam.CoordinateFrame.lookVector.X,cam.CoordinateFrame.lookVector.Y,0))
torso.CFrame = CFrame.new(Vector3.new(torso.Position.X+1*torso.CFrame.lookVector.X,torso.Position.Y+1*torso.CFrame.lookVector.Y,torso.Position.Z),torso.Position+Vector3.new(cam.CoordinateFrame.lookVector.X,cam.CoordinateFrame.lookVector.Y,0))*CFrame.Angles(0,math.pi,math.pi/2)
print(cam.CoordinateFrame.lookVector)
end
--Here is the problem-
The game will randomly break at some point when the player is moving on the wall. At that instance, the printed lookVector looks something like this-
-0.961045027, 0.276391804, -7.62939365e-008
I believe -7.62939365e-008 is the number in question. It seems whenever one of the lookVector's coordinates are 0 or close to 0, such as this one, the game breaks.
Why is this? |