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

How do I get this cannon to fire the way its facing?

Asked by 7 years ago
01c = script.Parent.click
02debounce = true
03as = Workspace.as
04 
05script.Parent.click.ClickDetector.MouseClick:connect(function()
06    if debounce == true then c.BrickColor = BrickColor.new("Really red")
07        debounce = false
08        pp = script.Parent.Barrel.Position
09        b = Instance.new("Part", game.Workspace)
10        fire = Instance.new("Fire", b)
11        b.Name = "Canon Ball"
12        b.BrickColor = BrickColor.new("Really black")
13        b.Shape = "Ball"
14        b.Size = Vector3.new(2, 2, 2)
15        b.Position = Vector3.new(pp.X, pp.Y , pp.Z)
View all 36 lines...

Ive tried everything. All the body positions, CFrame and I cant get the cannon ball to fire in the direction the cannon is facing. I tried making the cannon ball point in the direction of the cannon but being confined to XYZ I have no idea how to do it. - Thanks

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
1local direction = Barrel.CFrame:vectorToWorldSpace(Vector3.new(0,0,-1))  -- gets direction from middle of part to the front face
2 
3b.Position = Barrel.Position + ((2 + Barrel.Size.Z/2) * direction)  -- sets position to in front of the barrel
4 
5b.Velocity = direction * 500
0
Thanks birdeater11 14 — 7y
0
Btw ill give you credit in my game if I ever finish it birdeater11 14 — 7y
Ad

Answer this question