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

How would i make bullet go from the mouse position ?

Asked by 6 years ago

So. Im making a gun for a friend

I finished it then i started scripting it.

Now what i need is to make the 'local Bullet = Instance.new("Part",game.Workspace)' goes to the mouse position like in Phantom Force or Jailbreak.

I'm not asking for a script i'm just a noob in script and i don't know where to start.

Thanks

0
Use raycasting and make the bullet move along that INOOBE_YT 387 — 6y
0
Raycasting ? xJathur95x 129 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local player = game.Players.LocalPlayer -- Assuming this is a local script
local char = player.CharacterAdded:wait()
local mouse = player:GetMouse()

local Bullet = Instance.new("Part",game.Workspace)
local trajectory = CFrame.new(char.HumanoidRootPart.CFrame.p,mouse.Hit.p) -- Sets the bullet to character's HumanoidRootPart Position, while looking at the mouse's world Position.
Bullet.Anchored = true
Bullet.CFrame = trajectory

local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity = Bullet.CFrame.lookVector * 100 -- Multiplied by whatever speed you want.

Also if you want the bullet to spawn infront of the character replace the following line with this

Bullet.CFrame = trajectory *CFrame.new(0,0,-10) -- 10 studs infront of the character

And if you want the bullet to spawn out of the barrel of the gun, make sure you define it first

local barrel = GUNNAME.Barrel.CFrame.p
local trajectory = CFrame.new(barrel,mouse.Hit.p) * CFrame.new(0,0,-2) -- 2 studs infront of the barrel

If this helped you, please accept this answer.

0
do i need to parent "BV" to bullet ? or it work without parenting it xJathur95x 129 — 6y
0
Yes you would have to parent BV to the bullet. jackfrost178 242 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Bullet.CFrame = game.Players.LocalPlayer:GetMouse().Target

Does that work?

0
bad argument #3 to 'CFrame' (CFrame expected, got nil) xJathur95x 129 — 6y

Answer this question