#Straight shot

56 messages · Page 1 of 1 (latest)

vagrant schooner
#

I want to make a gun that shoots bullets in a straight line but cant figure out how.
The way i want it is: by clicking, the gun shoots a block that will travel for a period of time in a straight line, not effected by gravity ( no bullet drop) and thats all.
any way to achive that will be helpful.

vagrant schooner
#

i tried but cant seem to do it right, im a novice. do you know how?

umbral aurora
#

What didn't work?

vagrant schooner
#

it has a starting and end position but the bullets only go to the x axis

#

not by the gun

#

can i show the script?

umbral aurora
#

Yes

#

Use the fomatting

vagrant schooner
#

"lua local tool = script.Parent

tool.Activated:Connect(function()
local bullet = Instance.new("Part")
bullet.Position = tool.Handle.Position
bullet.Size = Vector3.new(0.2, 0.2, 0.2)
bullet.Color = Color3.new(1, 0, 0)
bullet.CanCollide = true
bullet.Anchored = false
bullet.Parent = game.Workspace

local startPos = bullet.Position -- starting position of the part
local endPos = startPos + Vector3.new(10, 0, 0) -- ending position of the part
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1) -- creates a TweenInfo object with duration of 5 seconds and repeating infinitely
local tween = game:GetService("TweenService"):Create(bullet, tweenInfo, {Position = endPos}) -- creates a new tween with the part as the object to tween, the TweenInfo object we created earlier, and the ending position we defined earlier
tween:Play() -- starts the tween

wait(2)
bullet:Destroy()

end) /"

umbral aurora
#

Not like that

quaint bone
vagrant schooner
#

i thank you for this but the problem is i have no idea how to write it

proven topazBOT
#

studio** You are now Level 1! **studio

umbral aurora
#

Does it work?

vagrant schooner
#

No, anything i try adding to the bullet related to moving does nothing

compact oriole
#

next time do this when adding code

#

its the key next to 1 and tab

quasi lynx
#

Since you have bullet travel time I recommend fastcast

compact oriole
#

He’s new so I imagine he doesn’t know what that is. If you wanna help I recommend linking what fast casting is

compact oriole
#

Since it’s bullet.Position + vector3.new(10,0,0)

vagrant schooner
#

yea pretty much

compact oriole
#

Do you know the directions of vector 3?

#

I’m assuming so

vagrant schooner
#

x,y,z

compact oriole
#

Bingo nice

#

So I do recommend look vector, do you understand how it works

#

Unless you want the bullet to go to the mouse

vagrant schooner
#

i only want it to go straight when clicked

compact oriole
#

Alright then lookvector

#

Do you want me to explain it or do you understand by reading up on it

vagrant schooner
#

please explain

compact oriole
#

Alright

#

So lookvextor basically goes however far forward from the part you want it to go. Let me explain

#

Lookvector * 5 will go 5 Studs

#

Forward

#

(One sec changing classes)

vagrant schooner
#

take your time i dont mind

quasi lynx
#

Lookvector is a direction

#

That has been normalized/turned into 1’s

#

The vector3 dictates where the part is looking at

#

Eulers angle I think

compact oriole
#

So how I would do it is I would do bullet position += base.Lookvector * 250(or whatever range)

#

Now some issues you might run into.

#

1.) your bullet teleports
You need to tween/lerp it. I can also explain that as well

2.) your bullet goes a random direction.
You need to make sure the front of the part is facing the front of the gun.

#

Any other questions lmk

#

Some additional information,

Lookvector * -number = backwards
Rightvector * number = right
Rightvector * -number = left
Upvector * number = up
Upvector * -number = down

vagrant schooner
#

exactly how can i tween/lerp it?

vagrant schooner
compact oriole
compact oriole