Why is the Guided Rocket Launcher going crazy? [closed]
Everytime the Guided Rocket Launches, The camera started getting glitch, Here's the script:
002 | local Tool = script.Parent |
003 | local Launcher = Tool.Handle |
005 | local Rocket = Instance.new( "Part" ) |
007 | Rocket.BackSurface = 3 |
008 | Rocket.BottomSurface = 3 |
009 | Rocket.FrontSurface = 3 |
010 | Rocket.LeftSurface = 3 |
011 | Rocket.RightSurface = 3 |
013 | Rocket.Size = Vector 3. new( 1 , 2.5 , 1 ) |
014 | Rocket.BrickColor = BrickColor.new( 23 ) |
018 | local rocketMesh = Instance.new( "SpecialMesh" ) |
021 | rocketMesh.Parent = Rocket |
023 | local debris = game:GetService( "Debris" ) |
031 | function blow(hit, missile) |
033 | game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid |
034 | game.Workspace.CurrentCamera.CameraType = "Custom" |
035 | if missile = = nil then return end |
036 | if swooshSound then swooshSound:stop() end |
037 | explosion = Instance.new( "Explosion" ) |
038 | explosion.Position = missile.Position |
040 | local creator = missile:FindFirstChild( "creator" ) |
041 | explosion.Hit:connect( function (part, distance) onPlayerBlownUp(part, distance, creator) end ) |
042 | explosion.Parent = game.Workspace |
043 | if explosionSound then explosionSound:Play() end |
045 | if missile then missile:Remove() end |
048 | function onPlayerBlownUp(part, distance, creator) |
049 | if part.Name = = "Head" or part.Name = = "Torso" then |
050 | local humanoid = part.Parent.Humanoid |
051 | tagHumanoid(humanoid, creator) |
055 | function tagHumanoid(humanoid, creator) |
057 | if creator ~ = nil then |
058 | local new_tag = creator:clone() |
059 | new_tag.Parent = humanoid |
063 | function fire(vTarget) |
064 | local vCharacter = Tool.Parent |
065 | local vHandle = Tool:findFirstChild( "Handle" ) |
066 | if vHandle = = nil then |
067 | print ( "Handle not found" ) |
070 | local direction = vTarget - vHandle.Position |
071 | direction = computeDirection(direction) |
072 | local missile = Rocket:clone() |
073 | local pos = vHandle.Position + (direction * 10.0 ) |
074 | missile.CFrame = CFrame.new(pos, pos + direction) * CFrame.Angles(math.pi/ 2 , 0 , 0 ) |
076 | local creator_tag = Instance.new( "ObjectValue" ) |
078 | local vPlayer = game.Players:GetPlayerFromCharacter(vCharacter) |
080 | if vPlayer = = nil then |
081 | print ( "Player not found" ) |
083 | if (vPlayer.Neutral = = false ) then |
084 | missile.BrickColor = vPlayer.TeamColor |
088 | local floatForce = Instance.new( "BodyForce" ) |
089 | floatForce.force = Vector 3. new( 0 , missile:GetMass() * 196.1 , 0.0 ) |
090 | floatForce.Parent = missile |
092 | missile.Velocity = computeDirection(Tool.Parent.Humanoid.TargetPoint - missile.Position) * 20.0 |
094 | creator_tag.Value = vPlayer |
095 | creator_tag.Name = "creator" |
096 | creator_tag.Parent = missile |
098 | missile.Parent = game.Workspace |
100 | if swooshSound then swooshSound:Play() end |
102 | missile.Touched:connect( function (hit) blow(hit, missile) end ) |
104 | debris:AddItem(missile, 100.0 ) |
105 | local cam = workspace.CurrentCamera |
106 | cam.CameraSubject = missile |
107 | cam.CameraType = "Follow" |
110 | direction = computeDirection(Tool.Parent.Humanoid.TargetPoint - missile.Position) |
111 | missile.Velocity = direction * 20.0 |
114 | missile.CFrame = CFrame.new(missile.Position, missile.Position + direction) * CFrame.Angles(math.pi/ 2 , 0 , 0 ) |
119 | function computeDirection(vec) |
120 | local lenSquared = vec.magnitude * vec.magnitude |
121 | local invSqrt = 1 / math.sqrt(lenSquared) |
122 | return Vector 3. new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt) |
126 | function onActivated() |
127 | if not Tool.Enabled then |
133 | local character = Tool.Parent; |
134 | local humanoid = character.Humanoid |
135 | if humanoid = = nil then |
136 | print ( "Humanoid not found" ) |
140 | swooshSound = Launcher:FindFirstChild( "Swoosh" ) |
141 | explosionSound = Launcher:FindFirstChild( "Explosion" ) |
143 | local targetPos = humanoid.TargetPoint |
153 | script.Parent.Activated:connect(onActivated) |