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

Innacurate Aiming with mouse... Any fixes?

Asked by 3 years ago

I've been working on my first magic script lately, and I've just noticed this "bug" or unwanted feature which is inaccuracy. This issue is so bad at the point the projectile can go over 100 studs away from the desired target.

This is the piece of code I've used that I am almost certain that contains the issue:

local bodyvel = Instance.new("BodyVelocity", Projectile)
    bodyvel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    bodyvel.Velocity = Mouse.lookVector * 150  -- Mouse in here is abbreviated for Mouse.Hit.Cframe. 

Here's a streamable link to a video where it's inaccuracy is shown. https://streamable.com/yiayq5

It really frustrated me. (It was supposed to land near the place with bent pillars.)

0
Shouldn't it be 'UnitRay' of the mouse rather than 'lookVector'? DiamondComplex 285 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

Wow! That video looked pretty cool! I suggest using Rays, Rays are a lot more accurate. (unless there is an invisible object in the way) Anyways, this is a basic script that should help:

local Workspace = game:GetService("Workspace")
local position = mouse.Hit.Position

local origin = YOUR_STARTING_PART.Position
local direction = (position - origin).Unit*300
local result = Workspace:Raycast(origin, direction)

local intersection = result and result.Position or origin + direction
local distance = (origin - intersection).Magnitude

local bullet_clone = LOCATE_PROJECTILE_HERE
bullet_clone.CFrame = CFrame.new(origin, intersection)*CFrame.new(0, 0, -distance/2)
bullet_clone.Parent = Workspace

You can play around with it, let me know if you have any questions!

0
This did fix my issue, although It generated some other issues which are easily fix-able. thank you! DatStxic 7 — 3y
Ad

Answer this question