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

How to use BodyForce the right way?

Asked by
lucas4114 607 Moderation Voter
8 years ago

I don't really know what to make the title for this so I made it that... So I am making a cannon, and everything works, the problem is when the cannon rotates to a different target, the cannon ball doesn't go out the cannon the right way, so lets say the cannon turned 45 degrees right but the cannon ball flys 45 degrees to the left, so it's like this, the cannon turned but the cannon ball still goes the same way as if the cannon hasn't even turned... Sorry if this might be hard to understand what I mean but please help? :c

Debounce = false

function Clicked()
    if Debounce == false then
        local Ball = Instance.new("Part")
        Ball.Name = "Bullet"
        Ball.Shape = "Ball"
        Ball.FormFactor = "Custom"
        Ball.Size = Vector3.new(0.6,0.6,0.6)
        Ball.Position = script.Parent.CannonBallSpawn.Position + Vector3.new(0,0,-1)
        Ball.Parent = game.Workspace
        local Force = Instance.new ("BodyForce")
        Force.force = Vector3.new(0,110,-90)
        Force.Parent = Ball
        Ball.BrickColor = script.Parent.Value.Value
        local Script = script.Parent.CannonBallScript:Clone()
        Script.Parent = Ball
        script.Parent.Button.BrickColor = script.Parent.Value2.Value
        Debounce = true
        wait(0.6)
        Force.force = Vector3.new(0,95,-85)
        wait(2)
        Force.force = Vector3.new(0,80,-75)
        wait(2)
        Force.force = Vector3.new(0,40,-50)
        Debounce = false
        script.Parent.Button.BrickColor = script.Parent.Value3.Value
    end
end

script.Parent.Button.ClickDetector.MouseClick:connect(Clicked)

Nothing in output.

0
The force of the BodyForce isn't relative to the object's location; Youll need to A. make the cannonball's rotation equal to that of the cannon, and B. make the force relative to the cannonball's rotation to make it fly forward, but ill leave that for you to figure out yourself. drew1017 330 — 8y
0
force of the BodyForce isn't relative to the object's rotation* drew1017 330 — 8y
0
Ok, I know what to do now I could use the rotation of the CannonBallSpawn then make that to the cannonBall. :D Ty lucas4114 607 — 8y

Answer this question