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
https://gyazo.com/98e39184844194ff1c043f03f3628da5

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, TweenInfo.new(8, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Value = CFrame.new(BallPos + Trajectory * 600)})
Tween:Play()

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(
	Ball, 
	TweenInfo.new(
		8, 
		Enum.EasingStyle.Linear, 
		Enum.EasingDirection.In
	), 
	{
		CFrame = CFrame.new(BallPos + Trajectory * 600)
	}
)

Tween:Play()

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