Nogalo
(Nogalo)
November 16, 2020, 9:03am
#1
Greetings,
I am trying to make a sort of projectile trajectory indicator, that would show the player how far the projectile will fly before disappearing. It is supposed to follow the mouse position. And i made it work with one critical issue, because of basic physics my indicator diverges from the mouse position. When my mouse is pointing into the sky, the indicator doesn’t quite follow it(even tho it does but because of math it doesn’t)
Here is how it looks https://streamable.com/kq75s7
Here is the script
local beam = Part:Clone()
beam.Parent = workspace
Mouse.TargetFilter = beam
game:GetService(“RunService”).RenderStepped:Connect(function()
beam.CFrame = Player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-.5)
beam.CFrame = CFrame.new(beam.Position, Mouse.Hit.p)
--wait (0.25)
local dist = (beam.Position- Mouse.Hit.p).Magnitude
local lenght = 75
if dist >= lenght then -
dist = lenght
end
beam.Size = Vector3.new(1,1,dist)
beam.CFrame = beam.CFrame * CFrame.new(0,0,-dist/2)
end)
Any advice would be greatly appreciated. Thank you for your time.
reygenne1
(chipgenne1)
November 16, 2020, 9:06am
#2
When you point the cursor in the air, it would be considered a nil value so you should probably use units or something like that i found in a community tutorial about recreating the lumber tycoon 2 hold system.
Nogalo
(Nogalo)
November 16, 2020, 9:20am
#3
sry I forgot to add the video, take a look to get what i mean
KJry_s
(MalleoZephyris)
November 16, 2020, 12:54pm
#4
Once you put your mouse in the sky the Mouse.Position would be infinite. What you gotta do instead is:
Get the camera and mouse position.
RealMousePos = (MousePos - CamPos).Unit * MaxStudLenght
Nogalo
(Nogalo)
November 16, 2020, 1:39pm
#5
could you please provide an example of how to implement this?
game:GetService(“RunService”).RenderStepped:Connect(function()
local RealMousePos = (Mouse.Hit.p - Camera.CFrame.Position).Unit * 75
beam.CFrame = Player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-.5)
beam.CFrame = CFrame.new(beam.Position, RealMousePos)
–wait (0.25)
local dist = (beam.Position- RealMousePos).Magnitude
local lenght = 75
if dist >= lenght then
dist = lenght
end
beam.Size = Vector3.new(1,1,dist)
beam.CFrame = beam.CFrame * CFrame.new(0,0,-dist/2)
end)
this is how i did it and it only got worse
reygenne1
(chipgenne1)
November 16, 2020, 1:56pm
#6
Use Mouse.Origin.p instead of the camera’s position, it is the origin point of the mouse starting at.
Nogalo
(Nogalo)
November 16, 2020, 2:01pm
#7
unfortunately that doesn’t solve the issue darn this seemed like a simple thing to do now it’s really grinding my gears