of     2   
chevron_rightchevron_rightchevron_right

kingkiller1000
#35014002Wednesday, October 06, 2010 10:30 PM GMT

I'm trying to make a lighting sword so that when you lunge it creates a "Lighting bolt" made of small parts that change CFrame as they go to anyone's torso that is within 30 studs. So when you fire, I want it to be like this: (sword holder)/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/(Target) ... But I really don't know how to do this... can I please have some help?
swimguy777
#35014206Wednesday, October 06, 2010 10:32 PM GMT

Raycasting? That's the only solution that I can think of. Don't ask me how to use it, though, cause I have NO idea :P
kingkiller1000
#35014560Wednesday, October 06, 2010 10:37 PM GMT

But Raycasting is one of the things I can't do... D:
kingkiller1000
#35014694Wednesday, October 06, 2010 10:39 PM GMT

Wait, this shouldn't involve raycasting...
crazypotato4
#35015403Wednesday, October 06, 2010 10:50 PM GMT

find a laser gun in free models or something and figure out how the laser thing works? unless you find a mesh, it might be hard to get the lightning shape... but you can just combine the scripts and it should give you a lightning sword o.0
Fungalmungal
#35021105Thursday, October 07, 2010 12:09 AM GMT

Determine the vector pointing from the sword to its target (subtract their positions), and determine the size that you want each part to be and the angle between them (I'll call this "angle"). Have the script produce a part with a CFrame such that it is facing in the direction of that vector, with its position at the sword, and rotate it by (angle - math.pi)/2 around its x-axis. Produce another part (Part.Size.y) * math.sin((angle/2)) units in front of the first, but rotated in the opposite direction, and repeat until the full length of the vector has been covered.
Ninja18340
#35023538Thursday, October 07, 2010 12:42 AM GMT

local Tool = script.Parent; enabled = true local spark = Instance.new("Fire") spark.Color = Color3.new(0,0,1) spark.Heat = 0 spark.SecondaryColor = Color3.new(0,0,1) spark.Size = 2 function fire(v) local vCharacter = Tool.Parent local vPlayer = game.Players:playerFromCharacter(vCharacter) local missile = Instance.new("Part") spark:Clone().Parent = missile local spawnPos = vCharacter.PrimaryPart.Position local PewPew = Tool.Handle:FindFirstChild("Sword") if (PewPew == nil) then PewPew = Instance.new("Sound") PewPew.Name = "Sword" PewPew.SoundId = "???" PewPew.Parent = Tool.Handle PewPew.Volume = 1 end spawnPos = spawnPos + (v * 10) missile.Position = spawnPos missile.Size = Vector3.new(1,1,1) missile.Velocity = v * 200 missile.Shape = 0 missile.BottomSurface = 0 missile.TopSurface = 0 missile.Name = "Spark" missile.Transparency = 1 local force = Instance.new("BodyForce") force.force = Vector3.new(0,98,0) force.Parent = missile local creator_tag = Instance.new("ObjectValue") creator_tag.Value = vPlayer creator_tag.Name = "creator" creator_tag.Parent = missile local new_script = script.Parent.LaserBlast:clone() new_script.Disabled = false new_script.Parent = missile missile.Parent = game.Workspace PewPew:Play() end function gunUp() Tool.GripForward = Vector3.new(0,.981,-.196) Tool.GripRight = Vector3.new(1,0,0) Tool.GripUp = Vector3.new(0,.196,.981) end function gunOut() Tool.GripForward = Vector3.new(0,1,0) Tool.GripRight = Vector3.new(1,0,0) Tool.GripUp = Vector3.new(0,0,1) end function onActivated() if not enabled then return end enabled = false local character = Tool.Parent; local humanoid = character.Humanoid if humanoid == nil then print("Humanoid not found") return end local targetPos = humanoid.TargetPoint local lookAt = (targetPos - character.Head.Position).unit local reload = .5 gunUp() fire(lookAt) wait(reload) gunOut() wait(reload) enabled = true end function onEquipped() Tool.Handle.EquipSound:play() end script.Parent.Activated:connect(onActivated) script.Parent.Equipped:connect(onEquipped)
Ninja18340
#35023660Thursday, October 07, 2010 12:43 AM GMT

I had to use the script for a gun because I've never made a sword that shot out like that. XD
GeneralFish
#35027438Thursday, October 07, 2010 1:35 AM GMT

If I remember correctly there is a lightning mesh, and btw it is called lightning not lighting, so the lightning is not so hard to do. I believe the formula for my raycasting is... local Place0 = START point AS a CFRAME value local target = END point As a Vector3 value Hit = CFrame.new(target) PART.Mesh.Scale = Vector3.new(Custom,Custom,(Place0.p-Hit.p).magnitude) PART.CFrame = CFrame.new((Place0.p + Hit.p)/2, Place0.p)
Fungalmungal
#35027833Thursday, October 07, 2010 1:42 AM GMT

There is no "formula" for raycasting. There are many ways to raycast, and many of them are too complex to be expressed as just a formula.
GeneralFish
#35027866Thursday, October 07, 2010 1:43 AM GMT

I'm saying that's the way I raycast my guns...
Fungalmungal
#35027974Thursday, October 07, 2010 1:45 AM GMT

That's not raycasting, though. Raycasting is a method of detecting intersections between a ray and planes or other objects.
kingkiller1000
#35028450Thursday, October 07, 2010 1:53 AM GMT

fungal has been the biggest help so far.
kingkiller1000
#35049789Thursday, October 07, 2010 8:12 PM GMT

@Ninja lol, I didn't want a gun, I said SWORD.
kingkiller1000
#35056365Thursday, October 07, 2010 9:52 PM GMT

@Fungal with the "Determine the vector pointing from the sword to its target (subtract their positions)" part, should I do the magnitude or just the (sword.Position - tor.Position)?
kingkiller1000
#35060541Thursday, October 07, 2010 10:54 PM GMT

I tried this, but it only makes one brick. tor = v.Torso local VectorPoint = (sword.Position - tor.Position) local size = 2 local Angle = 45 local m = Instance.new("Model", workspace) for i = 1, (sword.Position - tor.Position).magnitude do local p = Instance.new("Part", m) p.Anchored = true p.Size = Vector3.new(0, size, 0) p.BrickColor = BrickColor.new("Bright yellow") p.Reflectance = .5 p.CFrame = CFrame.new(sword.Position, tor.Position) p.CFrame = p.CFrame*CFrame.Angles(2*math.sin(45/2), 0, 0) game.Debris:AddItem(p, 2) end game.Debris:AddItem(m, 2)
kingkiller1000
#35067806Friday, October 08, 2010 12:28 AM GMT

Bump
Fungalmungal
#35068198Friday, October 08, 2010 12:34 AM GMT

The for loop should be for i = 1, math.ceil((sword.Position - tor.Position).magnitude / (math.sin(math.pi/8) * size)) do For the CFrame line, try p.CFrame = (CFrame.new(sword.Position, tor.Position) * CFrame.Angles( -.75/2 * math.pi * (-1^i),0,0)) + ((sword.Position - tor.Position).unit * math.sin(math.pi/8) * size)
Fungalmungal
#35068264Friday, October 08, 2010 12:35 AM GMT

Oops p.CFrame = (CFrame.new(sword.Position, tor.Position) * CFrame.Angles( -.75/2 * math.pi * (-1^i),0,0)) + ((sword.Position - tor.Position).unit * math.sin(math.pi/8) * size * i)
Fungalmungal
#35068320Friday, October 08, 2010 12:36 AM GMT

Gah... p.CFrame = (CFrame.new(sword.Position, tor.Position) * CFrame.Angles( -.75/2 * math.pi * ((-1)^i),0,0)) + ((sword.Position - tor.Position).unit * math.sin(math.pi/8) * size * i)
kingkiller1000
#35101812Friday, October 08, 2010 9:25 PM GMT

Which CFrame line? I have 2.
kingkiller1000
#35101947Friday, October 08, 2010 9:26 PM GMT

I assume the 2nd one, but I'm not sure.
Fungalmungal
#35102489Friday, October 08, 2010 9:33 PM GMT

Remove both lines and replace it with that.
kingkiller1000
#35103141Friday, October 08, 2010 9:41 PM GMT

Another problem I can't figure out: It keeps firing in the opposite direction. For example: \/\/\/\/\/\/\/\/\/\/\/\/\/\/(Sword Holder) ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­(Target) I tried fixing it, but I can't.
Fungalmungal
#35103334Friday, October 08, 2010 9:43 PM GMT

The lightning thing works? To reverse it, just swap the order of the positions p.CFrame = (CFrame.new(sword.Position, tor.Position) * CFrame.Angles( -.75/2 * math.pi * ((-1)^i),0,0)) + ((tor.Position - sword.Position).unit * math.sin(math.pi/8) * size * i)

    of     2   
chevron_rightchevron_rightchevron_right