Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with projectiles?

Asked by 8 years ago

For a project I'm making, it involves firing projectiles from the players torso. I'd like to make these projectiles aimable, so they fire in the direction the player is facing. Here's what I have so far.

    Player = script.Parent.Parent
Mouse = Player:GetMouse()
Character = Player.Character
function Damage(part)
    if part.Parent.Humanoid  and part.Parent.Name ~= Character.Name then
        Disc:Destroy()
        part.Parent.Humanoid.Health = part.Parent.Humanoid.Health - 25
    end
end
function onKeyDown(key)
    key = key:lower()
    if key == "f" then
        Disc = Instance.new("Part",workspace)
        game.Debris:AddItem(Disc,3)
        Disc.CFrame = CFrame.new(Character.Torso.Position,Mouse.Origin.p)
        Disc.Rotation = Vector3.new(Character.Torso.Rotation)
        Disc.CanCollide = false
        Disc.Transparency = 0.5
        Disc.BrickColor = BrickColor.new("Bright orange")
        Disc.Size = Vector3.new(2,2,2)
        Fire = Instance.new("Fire",Disc)
        Cylinder = Instance.new("CylinderMesh",Disc)
        Cylinder.Scale = Vector3.new(2.3,0.5,2.3)
        Velo = Instance.new("BodyVelocity",Disc)
        Velo.Velocity = Disc.CFrame.lookVector*90
        Velo.maxForce = Vector3.new(math.huge,math.huge,math.huge)
        DamageScript = game.ServerStorage.Script:Clone()
        wait(0.25)
        DamageScript.Disabled = false
        Sound = workspace.Sound:Clone()
        Sound.Parent = Disc
        game.Debris:AddItem(Sound,3)
        SP = math.random(60,80)/10
        SV = math.random(5,10)
        Sound.Volume = SV
        Sound.Pitch = SP
        Disc.Touched:connect(Damage)
    end
end
Mouse.KeyDown:connect(onKeyDown)

The projectiles does fire, but it only fires from one direction. Any ideas as to why this is not working?

0
You have lookvector from disk cframe, should be player's torso crame on line 25. This is a reason to why it is not moving..... my answer still stands koolkid8099 705 — 8y
0
I had figured that out earlier and forgot to get back to you. My apologies. Flyanide 40 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

The best way of having it go from the direction from torso would be by using lookVector, which is a child of cframe. This return the direction in which an object "Front" surface is facing. You should use this to increase the Velocity Sending the part flying into the direction. This would be done like so:

key = key:lower()
if key == "f" then
    Disc = Instance.new("Part",workspace)

    Disc.CFrame = Character.Torso.Rotation*CFrame.new(-2,-2,-2)--kept the rotation you had
    Disk.Velocity = Character.Torso.CFrame.lookVector * 100
end

So i kept the rotations u had and just added the "flying" part

0
Shouldn't have left out that I do have a bodyvelocity in there and the velocity is lookVector*90, however, let's say i was using mouselock and spinning around. It would still only shoot from one direction. Flyanide 40 — 8y
Ad

Answer this question