How would I be able to get accurate shots?

Hello everyone. I am currently working on a survival game that draws similarities from Rust and Unturned.

I’m currently trying to get bullets to shoot quite straight, but they don’t seem to be working perfectly.

The system I use for getting the bullet’s cframe is an attachment within the gun model called “bspawn”, which just tells my event where the CFrame is. The bullet spawns from the CFrame point, and it moves using this code every heartbeat :
Bullet.Projectile.CFrame = Bullet.Projectile.CFrame*(CFrame.new(0,0,-Bullet.CurrentSpeed))
What seems to happen though, is that the bullet somehow goes down.

For anyone wondering, the bspawn point is the tip of the rear sight.

bspawn

Does anyone know a way to eliminate the unexplained offset? Any help and or tips to improve anything would be greatly appreciated, as I have been accustomed to things completely unrelated to these types of things for the past few years. Thanks in advance.

Please inform me on how I can improve my posts, First post here.

2 Likes

I’ve noticed a few things that seem weird to me on this.
Is the Bullet.CurrentSpeed an IntValue? If so, use Bullet.CurrentSpeed.Value.
The reason your bullet goes down may be because it’s not following the LookVector. If you don’t know what LookVectors are, they are like directions of a CFrame. You have LookVector, RightVector, and UpVector. Try using Bullet.Projectile.CFrame = Bullet.Projectile.CFrame + (Bullet.Projectile.CFrame.LookVector * Bullet.CurrentSpeed).
I hope I helped.

1 Like

Currentspeed is just an integer. Dictates how fast or slow it goes, and your code basically got it, but I tried that and that still had the same effect. Thank you for your effort though :slight_smile:

1 Like

What did you try? I need more information to determine how to fix your problem.

1 Like

Just for now, I’ve tried moving my bspawn attachment. Still really doesn’t do much, I did use your code sample, but it basically did the exact same thing it was doing as the old line. My old solution was using body movers, but that went horribly haha

aside from the code that actually moves it, here is the spawn code

script.CreateBullet.Event:connect(function(data,cframe,player,wepdata)

    b = script.Round:Clone()

    b.Parent = workspace

    b.CFrame = cframe

    table.insert(Bullets,{Projectile = b,CurrentSpeed = 45,Player = player,Data = data,WepData = data,DecayTime = 25,Firetime = tick()})

    end)
1 Like

I think this is because the mouth of the gun is inevitably lower than the sight, so it’s impossible to match up exactly. This is actually a problem with real life guns. What some games do is they cast a ray from the sights then have the bullet head there from a velocity to maintain maximum accuracy. Just my theory though.

1 Like

I’d imagine you being correct, I’ve been messing around with my current speed var, setting it really low to see the exact movement. It seems to just go lower by itself, even though everything is centered. I’ll try and do that and see what happens.

1 Like

Is the bullet anchored? What is the current CFrame code moving the bullet?

1 Like

Current cframe code moving it was the one I originally showed, and the bullet is indeed anchored. I’m gonna try ancant’s idea, and see how that goes.

1 Like

How are you positioning the sight?

that got me a bit confused, but hopefully here is what you mean

Hey all, I figured out a solution. Kind of simple actually.

I did a bit of tinkering with the bspawn to make it match the offset and that seemed to help a lot.

Thank you to all who tried to help though :slight_smile: