Is this the right way to use it?
01 | function onKeyPress(inputObject, gameProcessedEvent) |
02 | if inputObject.KeyCode = = Enum.KeyCode.F then |
03 | local mouse = game.Players.LocalPlayer:GetMouse() |
04 | local gun = workspace.Turret.Gun 2 |
05 | local gunPos = gun.Position |
06 | local part = Instance.new( "Part" ,workspace) |
07 | part.Size = Vector 3. 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 |
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:
1 | Force = 1 --The force you want it to go |
2 | Part = game.Workspace.Part 1 |
3 | Part.Velocity = Vector 3. 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 |
06 | Force = 1 |
07 | Gravity = 1 --The Current Gravity of the Bullet 0-1 |0|None |.5|medium |1|Full |
08 | Part = game.Workspace.Part 1 |
09 | PreVelocity = game.Workspace.Vector 3 Value |
10 |
11 | --Taking the Vector3 of the Part's LookVector and putting it into "Vector3Value": |
12 | PreVelocity.Value = Vector 3. 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 |
16 | Part.Velocity = Vector 3. new(PreVelocity.Value.X,Part.Velocity.Y*Gravity,PreVelocity.Value.Z) |