|
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? |
|
|
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 |
|
|
But Raycasting is one of the things I can't do... D: |
|
|
Wait, this shouldn't involve raycasting... |
|
|
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 |
|
|
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. |
|
|
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)
|
|
|
I had to use the script for a gun because I've never made a sword that shot out like that. XD |
|
|
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) |
|
|
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. |
|
|
I'm saying that's the way I raycast my guns... |
|
|
That's not raycasting, though. Raycasting is a method of detecting intersections between a ray and planes or other objects. |
|
|
fungal has been the biggest help so far. |
|
|
@Ninja
lol, I didn't want a gun, I said SWORD. |
|
|
@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)? |
|
|
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) |
|
|
|
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) |
|
|
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) |
|
|
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) |
|
|
Which CFrame line? I have 2. |
|
|
I assume the 2nd one, but I'm not sure. |
|
|
Remove both lines and replace it with that. |
|
|
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. |
|
|
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) |
|