Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

0

btw the body force is in there for example

1 answer

✓ Accepted answer

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)

22 comments

0

Does this solve your problem? :D

0

Using Direct Velocity gives you more control

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

0

its keeps going down?

0

the bullet will just fall

0

the bullet will just fall

0

oops posted it twice

0

sorry, if you dont want the bullet to fall you put a 0 on the gravity

0

Different time zones eh :/

0

yah ok thanks i will test that

0

yah ok thanks i will test that

0

yah ok thanks i will test that

0

why did that post 3 times?

0

what would the volicety in workspace be?

0

also look at my question i changed it.

0

also look at my question i changed it.

0

the bullet is still falling but ill temper with the script

0

IT WORKED

0

THANK YOU SO MUCH!!

0

now how can i rotate the turret to make this work

0

like how can make the player rotate the turret and the bullet rotate with them?i

0

I just barley figured it out for myself so good timing :D

This discussion is preserved as it was. New answers, comments, and votes are closed.