In my game, the players camera center is used to determine where bullets should go. This is fine from a gameplay standpoint and works well. However, visually, it looks like this.
https://i.gyazo.com/b10600959ce12945fbedae9817ee23f6.gif
What I want is to change the projectile starting point (on the client, purely visual) so it can come out of a hand or a weapon or wherever I need it to come out. However when I change the origin, the visuals don’t match up with what’s actually happening.
https://i.gyazo.com/24dc369e9ab6e5b68670ccc3ea891014.gif
I am horrible at math and having a hard time trying to figure out how to make up for the difference visually while maintaining clarity.
Here is the code on the Client that is firing the projectile.
local currentCamera = workspace.CurrentCamera
local VIEWPORT_SIZE = currentCamera.ViewportSize -- current size of the screen -- if you're raycasting multiple times, this will have to be redefined!
local maxDistance = weaponAttributes["Max_Distance"]
local myParams = RaycastParams.new()
myParams.FilterType = Enum.RaycastFilterType.Exclude
myParams.FilterDescendantsInstances = {myCharacter}
local unitRay = currentCamera:ViewportPointToRay(VIEWPORT_SIZE.X / 2, VIEWPORT_SIZE.Y / 2)-- + game:GetService("GuiService"):GetGuiInset().Y) -- account for the 36px TopBar inset
module.abilityEvent:FireServer("PrimaryFire", {unitRay.Direction, unitRay.Origin})
And then the Server sends out an event with the important things so the clients can fire their own bullet. Currently it’s the same as the server where it just fires a FastCast cast with all the same attributes.
local simBullet = myCaster:Fire(origin, direction, weaponAttributes["Bullet_Speed"], CastBehavior)