Bullet is way off

I’m aware there are lots of posts with the same topics, however, all those use RayCasting, where I am not. The issue is, the bullet doesn’t go where the mouse is located at weird times/angles of the camera…

As shown:

The server script:

GunBullet.Position = Handle.Parent.Model.Point.Position
GunBullet.CFrame = CFrame.new(Handle.Parent.Model.Point.Position,hit)*CFrame.new(0,0,-50)
1 Like

This is because you added that extra cframe, that sets the ending position off 50 studs

3 Likes

Yeah, I just decided to do raycasting. It’s working like a charm, however, when the player moves, the bullet is behind a split of a second.

This is the server code:

local RayCast = Ray.new(Point,(hit-Point).unit*10)
local Part,Position,Normal = game.Workspace:FindPartOnRay(RayCast,player.Character, false,true)
local Dist = (hit-Point).magnitude
if not Dist then Dist = 50 end
if Dist > 50 then Dist = 50 end
local Lazer = Instance.new("Part")
Lazer.Parent = game.Workspace
Lazer.Material = Enum.Material.Neon
Lazer.BrickColor = BrickColor.new("New Yeller")
Lazer.Anchored = true
Lazer.CanCollide = false
Lazer.Size = Vector3.new(0.1,0.1,Dist)
Lazer.CFrame = CFrame.new(Point,Position)*CFrame.new(0,0,-Dist/2)
game.Debris:AddItem(Lazer,0.2)

Does it just take too long to create the part? That’s what I’m thinking.

It’s because of latency. I’m just going to let the server handle the ray casting involving the damage. While the client will see the bullet.

Most of the time guns don’t use this “beam” effect to show where you are shooting. Your bullet is actually going in the correct direction, but the beam, since its not long enough, is giving the illusion that it’s not.

A lot of games use a traveling projectile to represent a bullet, rather than using a beam straight from the barrel to the destination.

In the gif of your reply above, the beam lags behind when you move. This is a big reason why this method of bullet tracing makes no sense.

What you can use is an actual beam and have one of the attachments to the gun so that way it stays with the gun

@Virvek when you raycast o the server, there is a split second wait. This causes the “lag” between beginning points. I do however, advise projectiles. That would mean a single part looped in the direction of the mouse hit along the path of a ray created in the loop.

I specialize in the creation of the projectile method, so I’d be happy to help you. Also, if you plan on allowing visuals on the client, that is a good idea. Also you should do hit detection on the server.

Just gonna put this out there for people who were having the same issue I was having.

I don’t know how great this method is, but it’s working cosmetically flawless for me. There COULD be some drawback using it.

I basically create two raycasts, one on the client, and one on the server. The raycast on the client is strictly for the bullet cosmetic.

I then have an event called DrawRaycast which passes a table of arguments so the server can create it’s raycast and pass those arguments on to all other clients that need to see the bullet by using an event I place in ReplicatedStorage called DrawLaser.

Here’s what it looks like in code:

Creating the raycast

Making a table of arguments to send to the server

Creating the bullet for the client that is shooting

The most important part about the above is that we are binding “BindCFrame” to RenderStep which will constantly update the bullet’s CFrame, giving you that seamless and non-lagging behind effect everyone wants with raycast.

Making the event that will create the bullet for all other clients that DID NOT SHOOT THE BULLET

Again, we’re binding to renderstep, but this time we use the arguments that the server sent to us (a table of them) and set Origin, or whatever you call the variable that holds the position of where the bullet starts, to the correct CFrame. The reason we I included the “ShootPoint” into the arguments table is so the other clients could easily get the newest position of that because it’s where the bullet comes from.

Then, the server is probably the easiest part here

But yeah, like I said, feel free to critique this, I have no idea how this will even hold up but yeah, that’s how I got it to work for me.

Thanks to @KeysOfFate @Physicism @WingItMan for the help on my previous threads about Raycasting.

4 Likes