I need to get a new position using a position, direction and maximum length
This is what I use when I already know 2 positions
p.CFrame = CFrame.new(pos,MuzzlePos)*CFrame.new(0,0,-s/2)
but…
Variables
--Variables
local raycastparams = RaycastParams.new()
raycastparams.FilterDescendantsInstances = {player.Character, game.Workspace.Bullets, game.Workspace.Discoveries}
raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
raycastparams.IgnoreWater = true
local raycastResult = workspace:Raycast(MuzzlePos, dir.unit*maxrange,raycastparams)
--MuzzlePos is the first Vector3 position. It's just the position of the gun's muzzle in the workspace.
--In this case for example, maxrange = 500 Studs
local mousePos = mouse.Hit.Position
local direction = (mousePos - MuzzlePos).Unit * maxrange
--[[
local pos = raycastResult.Position When the gun is fired at something within 500 studs, I get this. However in this scenario, I don't. But the variable which comes after this is useless since the part is just going to be 500 studs long anyways.
]]
local s = (pos-MuzzlePos).magnitude
I’ve tried other ways but they were all botched attempts/edits and they all failed. I don’t know how to proceed from here with all the known variables either.