So I’m making an fps game and Im using fast cast with bullets that are basically a part with a trail.
The issue is that when i stay still the bullet shoots normally out of the tip of the gun, but when i walk there’s a “miss positioning” happening ( the bullet appears slightly moved on the X- Axis [if im moving left or right] and on the Y-axis[if im jumping].
I’m having the same problem, you can offset the Bullet by adding a Vector3 to the Origin of the Raycast. Im sure you can pass the MoveDirection of your Humanoid everytime you shoot, add the MoveDirection to the Origin and adjust by multiplying the vector.
Yes, I’ve thought of that but I can’t implement it. Here is my code local origin = viewmodel.Gun.ShootPart.Position game.ReplicatedStorage.SoundEvent:FireServer(false, true, script.Parent.Equippment.PrimaryServer.Value) local direction = (mouse.Hit.Position - origin).Unit caster:Fire(origin, direction, 500, castBehavior)
If the bullet is created on the server, then that’s because of the latency. What you can do is, make the bullet spawn on the client. (Simulate bullet) Just like what FE gun kit did. Well, basically almost what every shooter game did.
You can use Bullet:SetNetworkOwner(player), player being the one passed by the RemoteEvent. In the client script you pass the Character.Humanoid.MoveDirection, for example:
As others mentioned its because of the server sided bullet that is inherent in fast cast. You could try altering code to where it will predict its next position but that might be cumbersome endeavor
I’m making a fastcast on the server that is invisible and doesn’t use a cosmetic bullet that way I do the hit detection on the server, and i also make another fastcast on the client that doesnt do damage, but uses a cosmetic bullet - tracer. So basically I’m already doing the visuals on the client.
nvm, I tried adding the move direction and it worked perfectly sorry for the miss understanding !
BUT there’s another thing i need to fix : Well the movement is fixed but when i jump up and down , the tracer still appears under or above the fire point. The moveDirection property of the humanoid doesn’t check the Y velocity, Is there something i can add to the origin so the same way even if I’m jumping?
hmm, im not sure if you can do the same with jumping, but you could make a raycast directly facing the point under the player. Next, get the distance of the raycast by using raycastResult.Distance and add that to the offset using Origin + Vector3.new(0, raycastResult.Distance * someFactor, 0) make sure to add the character to the raycastParams. Ill try to search for a solution and if i find something, ill tell you. You can also try to just remove jumping or decrease the jumpheight, but only if it fits the game style youre going for.
Found something! you can use character.HumanoidRootPart.Velocity. it works great, because it returns a positive value and a negative value when falling down. You (again) should pass the HumanoidRootPart.Velocity.Y onto the server and add it to the Origin like this: Origin + Vector3.new(0, HrpVelocityY * someAdjustment, 0). im very sure it will work, just try changing the someAdjustment variable until it fits your needs. If you need me to write a small script like I did above, don’t hesitate. If there are any other problems, then tell me
Great to hear! Make sure to mark this comment with the solution checkmark. you can also combine the both into one and pass it like that onto the server:
-- client
local OffsetVector = Humanoid.MoveDirection + Vector3.new(0, HumanoidRootPart.Velocity.Y * someAdjustment, 0)
FireEvent:FireServer(..., Offset)
-- server
FireEvent.OnServerEvent:Connect(function(player, ..., Offset)
local Origin = viewmodel.Gun.ShootPart.Position + Offset
-- fastcast with the new origin
end)