I want the bullets to accurately fire from the starting position
What is the issue?
Whenever I move, the bullets are offset by a wide margin depending on where I aim at
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I am aware that a similar post was made here Projectile Offset When the Player is Moving, but there wasn’t a definite solution regarding this problem. I am also aware that the bullet will be delayed on the server before it begins shooting, which I have made to run under the client for instant feedback.
The gray block is where the bullet should start. The green dot is created with the bullet’s position when finalized, and the red dot is created with the position of the gray block.
I noticed that in first person, the problem no longer persisted. I would assume the problem resides in the following code that allows my character to look at my mouse, but if anyone thinks the problem is otherwise, feel free to let me know.
-- Character looks at mouse code
RunService.RenderStepped:Connect(function()
local RootPos, MousePos = player.Character.HumanoidRootPart.Position, mouse.Hit.Position
player.Character.HumanoidRootPart.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
end)
Is this something minuscule that I should not worry about, or is there a better code where I can keep the character looking at the direction I am pointing at all times?
Oh really? I didn’t know velocity sets the spawn position, I thought it was used to give it movement in one direction, similarly to apply force. I also have tried fast cast before, but from what I remember last time, the projectile was very jittery when I tested it out. I will stick to programming this feature normally, but I will look into it again
When looking into this spawn position thing, I tried to remove the velocity so the bullet would float in place, but turns out it still has the same behavior as last time, so it’s probably not the velocity.
That’s what the code is showing. The force you see that is labeled force is the bullet slowly floating down (aka bullet drop). The force that moves the bullet forward would be the velocity.