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?
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