Mouse hit isn't accurate

when I’m trying to “throw” an object to mouse position
it doesn’t go to exactly the mouse position, this is an example

the hit position is not accurate at all, sometime it is but most of the time it isn’t
I have tried searching on the developer forum and I found this thread

This is the part of the code that moves the object to the position

local Trajectory = (Hit.Position - BallPos).Unit
local Tween = TweenService:Create(CFValue,, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Value = + Trajectory * 600)})

I am using tweens for now but I don’t think it should change anything.

What happens when you remove the .Unit and remove the Trajectory * 600 from your code?

the object won’t move, BallPos is the position of the object before throwing

Is CFValue hooked up to a weld? Is it in object space?

CFValue is a random value I created so I can do :SetPrimaryPartCFrame
before the tween I set it to the object’s CFrame

In my test it seems to work as expected.

local TweenService = game:GetService("TweenService")

local Hit = game.Workspace.A
local Ball = game.Workspace.B

local BallPos = Ball.Position
local Trajectory = (Hit.Position - BallPos).Unit

local Tween = TweenService:Create(
		CFrame = + Trajectory * 600)


Test.rbxl (29.1 KB)

Note, to get a position from mouse hit you need to do Mouse.Hit.p

I disagree. You should be using UserInputService instead for this.

Whatever you want, used this method for over 10 years.
Both work, as long as it works it’s preference

1 Like

Turns out it was Mouse.TargetFilter, mouse.Hit didn’t pass through the object, after putting the object into mouse.TargetFilter I think it works

1 Like