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 5 years ago
Edited 5 years ago

Is this the right way to use it?

01function onKeyPress(inputObject, gameProcessedEvent)
02    if inputObject.KeyCode == Enum.KeyCode.F then
03    local mouse = game.Players.LocalPlayer:GetMouse()
04    local gun = workspace.Turret.Gun2
05    local gunPos= gun.Position
06    local part = Instance.new("Part",workspace)
07    part.Size = Vector3.new(1,1,2)
08    part.Material = "SmoothPlastic"
09    part.Position = gunPos
10    part.CanCollide = false
11--Workspace
12--  Part1
13--  Vector3Value
14 
15--I am using a Vector3 Value named "Vector3Value" (the object type) to not interfere in the current Velocity
View all 36 lines...
0
btw the body force is in there for example Nervousmrmonkey2 118 — 5y

1 answer

Log in to vote
1
Answered by
Nootian 184
5 years ago
Edited 5 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:

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

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

01--Workspace
02--  Part1
03--  Vector3Value
04 
05--I am using a Vector3 Value named "Vector3Value" (the object type) to not interfere in the current Velocity
06Force = 1
07Gravity = 1 --The Current Gravity of the Bullet 0-1  |0|None  |.5|medium |1|Full
08Part = game.Workspace.Part1
09PreVelocity = game.Workspace.Vector3Value
10 
11--Taking the Vector3 of the Part's LookVector and putting it into "Vector3Value":
12PreVelocity.Value = Vector3.new(Part.CFrame.LookVector * Force)
13 
14--Stripping the Y Value and using only the X/Z Values for Custom Gravity
15--Then placing the current Y value of "Part1" into the Velocity
16Part.Velocity = Vector3.new(PreVelocity.Value.X,Part.Velocity.Y*Gravity,PreVelocity.Value.Z)
0
Does this solve your problem? :D Nootian 184 — 5y
0
Using Direct Velocity gives you more control Nootian 184 — 5y
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 — 5y
0
its keeps going down? Nervousmrmonkey2 118 — 5y
View all comments (18 more)
0
the bullet will just fall Nervousmrmonkey2 118 — 5y
0
the bullet will just fall Nervousmrmonkey2 118 — 5y
0
oops posted it twice Nervousmrmonkey2 118 — 5y
0
sorry, if you dont want the bullet to fall you put a 0 on the gravity Nootian 184 — 5y
0
Different time zones eh :/ Nootian 184 — 5y
0
yah ok thanks i will test that Nervousmrmonkey2 118 — 5y
0
yah ok thanks i will test that Nervousmrmonkey2 118 — 5y
0
yah ok thanks i will test that Nervousmrmonkey2 118 — 5y
0
why did that post 3 times? Nervousmrmonkey2 118 — 5y
0
what would the volicety in workspace be? Nervousmrmonkey2 118 — 5y
0
also look at my question i changed it. Nervousmrmonkey2 118 — 5y
0
also look at my question i changed it. Nervousmrmonkey2 118 — 5y
0
the bullet is still falling but ill temper with the script Nervousmrmonkey2 118 — 5y
0
IT WORKED Nervousmrmonkey2 118 — 5y
0
THANK YOU SO MUCH!! Nervousmrmonkey2 118 — 5y
0
now how can i rotate the turret to make this work Nervousmrmonkey2 118 — 5y
0
like how can make the player rotate the turret and the bullet rotate with them?i Nervousmrmonkey2 118 — 5y
0
I just barley figured it out for myself so good timing :D Nootian 184 — 5y
Ad

Answer this question