- What do you want to achieve?
I want to create an accuracy spread for my gun to mimic where the higher the number, the worse the accuracy becomes.
- What is the issue?
The current issue is that my bullet becomes less accurate the close the enemy is at. I want it so that my accuracy spread is constant regardless of the distance of the enemy.
Noticed how I aim outside of the part which gave a much more accurate spread compared to if I aim at the block shown on the right. (I know that mouse.hit.p is affecting this)
- What solutions have you tried so far?
I attempted to filter out the workspace with TargetFilter for the mouse. However, this causes the bullet to be offset from the original crosshair, which may be off-putting for new players that are playing my game for the first time.
Current accuracy system:
local bulletPosition = mouse.Hit.p + Vector3.new(-ACCURACY_PENALTY + math.random() * ACCURACY_PENALTY * 1.5, -ACCURACY_PENALTY + math.random() * ACCURACY_PENALTY * 1.5, -ACCURACY_PENALTY + math.random() * ACCURACY_PENALTY * 1.5)
-- The vector3 mimics the accuracy pattern expected from rng.
-- If there's a better rng system I can use, let me know!
cloneBullet.CFrame = script.Parent.Weapon.bulletSpot.CFrame
-- sets starting position at the barrel of the gun.
cloneBullet.CFrame = CFrame.new(cloneBullet.Position, bulletPosition)
-- make the bullet face the mouse position
cloneBullet.Velocity = CFrame.new(localPlayer.Character.Head.Position, bulletPosition).lookVector * BULLET_SPEED
-- adds velocity to bullet to fly towards mouse position
I am thinking that I should create a spread that does not include the mouse.hit.p, but I’m not sure how to go at that.