GalPlayss
(GalPlayss)
July 14, 2022, 6:49pm
#1
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
Maybe try this? You could try setting the CFrame of the Projectile in relation to where the part first spawns and where the Mouse hits, then multiplying it by how fast you want it to go:
local Speed = 80
local Trajectory = CFrame.new(HumanoidRootPart.Position, mouse).LookVector
BodyVelocity.Velocity = Trajectory * Speed
Idk this is what I remember from projectiles, and it seems to work for some reason
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?
GalPlayss
(GalPlayss)
July 14, 2022, 6:52pm
#3
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?
GalPlayss
(GalPlayss)
July 14, 2022, 6:56pm
#5
CFValue is a random value I created so I can do :SetPrimaryPartCFrame
before the tween I set it to the object’s CFrame
Nitefal
(Nitefal)
July 14, 2022, 7:00pm
#6
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.
Nitefal
(Nitefal)
July 14, 2022, 7:05pm
#8
Whatever you want, used this method for over 10 years.
Both work, as long as it works it’s preference
1 Like
GalPlayss
(GalPlayss)
July 14, 2022, 7:13pm
#9
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