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

What do i use to get i bullet to go straight? BodyForce exc

Asked by 4 years ago
Edited 4 years ago

Is this the right way to use it?

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.F then
    local mouse = game.Players.LocalPlayer:GetMouse()
    local gun = workspace.Turret.Gun2
    local gunPos= gun.Position
    local part = Instance.new("Part",workspace)
    part.Size = Vector3.new(1,1,2)
    part.Material = "SmoothPlastic"
    part.Position = gunPos
    part.CanCollide = false
--Workspace
--  Part1
--  Vector3Value

--I am using a Vector3 Value named "Vector3Value" (the object type) to not interfere in the current Velocity
local Force = 1
local Gravity = 1 --The Current Gravity of the Bullet 0-1  |0|None  |.5|medium |1|Full
local PreVelocity = game.Workspace.Vector3Value
PreVelocity.Value = Vector3.new(part.CFrame.LookVector * Force)
part.Velocity = Vector3.new(PreVelocity.Value.X,part.Velocity.Y*Gravity,PreVelocity.Value.Z)

    part.Touched:connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 3000
    end
    end)
    end 






end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

0
btw the body force is in there for example Nervousmrmonkey2 118 — 4y

1 answer

Log in to vote
1
Answered by
Nootian 184
4 years ago
Edited 4 years ago

A regular Part in the workspace has a property called: Velocity, if you give it a constant value and get the look vector, you can move it in a certain direction going straight. For instance:

Force = 1 --The force you want it to go
Part = game.Workspace.Part1
Part.Velocity = Vector3.new(Part.CFrame.LookVector * Force)

Or you can add a custom Y value, so it has gravity

--Workspace
--  Part1
--  Vector3Value

--I am using a Vector3 Value named "Vector3Value" (the object type) to not interfere in the current Velocity
Force = 1
Gravity = 1 --The Current Gravity of the Bullet 0-1  |0|None  |.5|medium |1|Full
Part = game.Workspace.Part1
PreVelocity = game.Workspace.Vector3Value

--Taking the Vector3 of the Part's LookVector and putting it into "Vector3Value":
PreVelocity.Value = Vector3.new(Part.CFrame.LookVector * Force)

--Stripping the Y Value and using only the X/Z Values for Custom Gravity
--Then placing the current Y value of "Part1" into the Velocity
Part.Velocity = Vector3.new(PreVelocity.Value.X,Part.Velocity.Y*Gravity,PreVelocity.Value.Z)

0
Does this solve your problem? :D Nootian 184 — 4y
0
Using Direct Velocity gives you more control Nootian 184 — 4y
0
ok thanks but if i move the turret will the velocity go in the same direction as the turret when the turret moved? or will it go its normal direction Nervousmrmonkey2 118 — 4y
0
its keeps going down? Nervousmrmonkey2 118 — 4y
View all comments (18 more)
0
the bullet will just fall Nervousmrmonkey2 118 — 4y
0
the bullet will just fall Nervousmrmonkey2 118 — 4y
0
oops posted it twice Nervousmrmonkey2 118 — 4y
0
sorry, if you dont want the bullet to fall you put a 0 on the gravity Nootian 184 — 4y
0
Different time zones eh :/ Nootian 184 — 4y
0
yah ok thanks i will test that Nervousmrmonkey2 118 — 4y
0
yah ok thanks i will test that Nervousmrmonkey2 118 — 4y
0
yah ok thanks i will test that Nervousmrmonkey2 118 — 4y
0
why did that post 3 times? Nervousmrmonkey2 118 — 4y
0
what would the volicety in workspace be? Nervousmrmonkey2 118 — 4y
0
also look at my question i changed it. Nervousmrmonkey2 118 — 4y
0
also look at my question i changed it. Nervousmrmonkey2 118 — 4y
0
the bullet is still falling but ill temper with the script Nervousmrmonkey2 118 — 4y
0
IT WORKED Nervousmrmonkey2 118 — 4y
0
THANK YOU SO MUCH!! Nervousmrmonkey2 118 — 4y
0
now how can i rotate the turret to make this work Nervousmrmonkey2 118 — 4y
0
like how can make the player rotate the turret and the bullet rotate with them?i Nervousmrmonkey2 118 — 4y
0
I just barley figured it out for myself so good timing :D Nootian 184 — 4y
Ad

Answer this question