Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RayBase = workspace.Model.RayBase
- function RenderRay(R)
- local Part = Instance.new("Part")
- local RayLength = ( (R.Origin + R.Direction) - R.Origin ).magnitude
- Part.Size = Vector3.new(0,0,RayLength)
- Part.CFrame = CFrame.new(R.Origin, R.Origin + R.Direction) * CFrame.new(0,0,RayLength/-2)
- Part.BrickColor = BrickColor.Yellow()
- Part.Anchored = true
- Part.Name = "Ray"
- Part.Parent = workspace
- end
- do
- -- Cast ray in direction of RayBase's front surface
- local R = Ray.new(RayBase.Position, RayBase.CFrame.lookVector * 500)
- local HitPart, HitPoint, Normal = workspace:FindPartOnRay(R, RayBase)
- -- Override normal
- Normal = Vector3.new(Normal.Y, Normal.Z, Normal.X)
- --Normal = Vector3.new(0,1,0)
- -- Draw the initial ray
- RenderRay( Ray.new(RayBase.Position, RayBase.CFrame.lookVector * (HitPoint - RayBase.Position).magnitude) )
- -- Calculate the direction of the reflected ray
- local ClosestPointOnNormalLine = Ray.new(HitPoint, Normal):ClosestPoint(RayBase.Position)
- local Alpha = (ClosestPointOnNormalLine - RayBase.Position).magnitude
- local ReflectionDirection = (((2 * Normal) * (R.Unit.Direction:Dot(Normal))) - (1 * R.Unit.Direction)).unit
- local ReflectedRay = Ray.new(HitPoint, ReflectionDirection * 100, HitPart)
- RenderRay(ReflectedRay)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement