Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Bullet spread math doesnt seem to be working correctly?

Asked by 5 years ago

I am trying to do bullet spread and I think ive got it almost done im just having problems with the bullets not going to where the mouse.hit is.

Heres my code right now and also a gif of whats happening.

local Direction = CFrame.new(Tool.Barrel.CFrame.Position, Mouse.Hit.Position) * CFrame.new(math.random(-10, 10), math.random(-10, 10), math.random(-10, 10)).LookVector

local BulletRay = Ray.new(Tool.Barrel.CFrame.Position, Direction.Unit * 1000)

https://gyazo.com/907902b0b2e1b3e6a0969a335f69814d

Anyone have any ideas? Thank you for your time :)

0
It's because in getting your direction, you are multiplying a CFrame by a lookVector to get a direction, which isn't a good way to find a direction. Instead, I would recommend getting the lookVector of the first CFrame and offset the Mouse.Hit position by a random number to still get that bullet spread effect. You could base the offset off of the magnitude between the tool's position and the Mouse jharnekus 3 — 5y
0
learn back math my dude LightModed 81 — 5y
0
@LightModed You are edgy stay away from me normie. GottaHaveAFunTime 218 — 5y

Answer this question