How would I prevent the brick from going around the block it is placed?
The brick, "LightExplosion" is a ball part that is fired with a laser and then rapidly expands to its size. The issue is when it resizes it goes around blocks instead of cframing into them and it only happens with the onTouch function. When the function is removed it works fine. How would I fix the function to where it doesn't force the ball to go over the designated part and instead half into it? Here's the code causing the problem:
03 | local Debris = game:GetService( 'Debris' ) |
06 | local CharacterToIgnore = script:WaitForChild( 'CharacterToIgnore' ).Value |
12 | local TIME_OF_FORCE = 0.2 |
15 | local Part = script.Parent |
16 | Part.Touched:connect( function (other) |
17 | Part.CanCollide = false |
22 | if other.Parent = = CharacterToIgnore or (other.Parent and other.Parent.Parent = = CharacterToIgnore) then return end |
24 | if not other.Anchored then |
30 | local direction = (other.Position - Part.Position).unit |
32 | local bodyForce = Instance.new( 'BodyForce' ) |
34 | bodyForce.force = MAGNITUDE * direction |
36 | local Debris = game:GetService( 'Debris' ) |
39 | local CharacterToIgnore = script:WaitForChild( 'CharacterToIgnore' ).Value |
45 | local TIME_OF_FORCE = 0.2 |
48 | local Part = script.Parent |
49 | Part.Touched:connect( function (other) |
50 | Part.CanCollide = false |
55 | if other.Parent = = CharacterToIgnore or (other.Parent and other.Parent.Parent = = CharacterToIgnore) then return end |
57 | if not other.Anchored then |
63 | local direction = (other.Position - Part.Position).unit |
65 | local bodyForce = Instance.new( 'BodyForce' ) |
67 | bodyForce.force = MAGNITUDE * direction |
69 | bodyForce.Parent = other |
71 | Debris:AddItem(bodyForce, TIME_OF_FORCE) |
78 | bodyForce.Parent = other |
80 | Debris:AddItem(bodyForce, TIME_OF_FORCE) |
Here's the code where the ball is actually created:
001 | local tool = script.Parent |
002 | local player = game:GetService( "Players" ).LocalPlayer |
004 | local beam = Instance.new( "Part" , workspace) |
007 | tool.Equipped:connect( function (mouse) |
008 | print ( "Tool equipped!" ) |
010 | mouse.Button 1 Down:connect( function () |
012 | script.Disabled = true |
013 | script.Parent.Sound:Play() |
015 | print ( "Mouse pressed!" ) |
017 | local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300 ) |
018 | local part, position = workspace:FindPartOnRay(ray, player.Character, false , true ) |
021 | beam.BrickColor = BrickColor.Yellow() |
022 | beam.FormFactor = "Custom" |
023 | beam.Material = "Neon" |
024 | beam.Transparency = 0.25 |
027 | beam.CanCollide = false |
029 | beam.Name = "LightExplosion" |
039 | local distance = (tool.Handle.CFrame.p - position).magnitude |
040 | beam.Size = Vector 3. new( 1 , 1 , 1 ) |
041 | beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new( 0 , 0 , -distance / 1 ) |
042 | beam.Size = Vector 3. new( 2 , 2 , 2 ) |
043 | local scriptCopy = game.ReplicatedStorage.RepelScript:Clone() |
044 | scriptCopy.Parent = game.Workspace.LightExplosion |
045 | beam.BrickColor = BrickColor.new( "Orange" ) |
047 | beam.Size = Vector 3. new( 3 , 3 , 3 ) |
048 | beam.BrickColor = BrickColor.new( "Orange" ) |
050 | beam.Size = Vector 3. new( 4 , 4 , 4 ) |
051 | beam.BrickColor = BrickColor.new( "Orange" ) |
053 | beam.Size = Vector 3. new( 5 , 5 , 5 ) |
054 | beam.BrickColor = BrickColor.Yellow() |
056 | beam.Size = Vector 3. new( 6 , 6 , 6 ) |
057 | beam.BrickColor = BrickColor.new( "Orange" ) |
059 | beam.Size = Vector 3. new( 7 , 7 , 7 ) |
060 | beam.BrickColor = BrickColor.Yellow() |
062 | beam.Size = Vector 3. new( 8 , 8 , 8 ) |
063 | beam.BrickColor = BrickColor.new( "Orange" ) |
065 | beam.Size = Vector 3. new( 9 , 9 , 9 ) |
066 | beam.BrickColor = BrickColor.Yellow() |
068 | beam.Size = Vector 3. new( 10 , 10 , 10 ) |
069 | beam.BrickColor = BrickColor.new( "Orange" ) |
071 | beam.Size = Vector 3. new( 11 , 11 , 11 ) |
072 | beam.BrickColor = BrickColor.Yellow() |
074 | beam.Size = Vector 3. new( 12 , 12 , 12 ) |
075 | beam.BrickColor = BrickColor.new( "Orange" ) |
077 | beam.Size = Vector 3. new( 13 , 13 , 13 ) |
078 | beam.BrickColor = BrickColor.Yellow() |
080 | beam.Size = Vector 3. new( 14 , 14 , 14 ) |
081 | beam.BrickColor = BrickColor.new( "Orange" ) |
083 | beam.Size = Vector 3. new( 15 , 15 , 15 ) |
084 | beam.BrickColor = BrickColor.Yellow() |
090 | game:GetService( "Debris" ):AddItem(beam, 1 ) |
092 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
095 | humanoid = part.Parent.Parent:FindFirstChild( "Humanoid" ) |
099 | humanoid:TakeDamage( 30 ) |
101 | script.Parent.Reload.Disabled = false |