Need help with character positioning

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Teleport to a target facing them a few studs away.

  2. What is the issue? Include screenshots / videos if possible!
    Don’t know the math to position it that way

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Tried using math and it didnt work

return function(info)
	local plr : Player = info.plr
	local char : Model = plr.Character
	
	local root : BasePart = char.HumanoidRootPart
	
	local ability = info.ability
	local userId : number = plr.UserId or char.UserId.Value
	
	local MouseCf = info.MouseCFrame
	local pos = info.cf
	
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = {workspace.CharacterHitboxes}
	params.FilterType = Enum.RaycastFilterType.Include
	
	local ray = workspace:Raycast(pos, (MouseCf-pos).Unit*150, params)
	
	if ray then
		local target = ray.Instance.Character.Value
		local humrp = target.HumanoidRootPart
		
		root.Position = ray.Position
		root.CFrame = CFrame.lookAt(root.Position, humrp.Position)
	end
end


Trying to position it a few studs away from the target.

local target = ray.Instance.Character.Value
		local humrp = target.HumanoidRootPart
		
		local difference = humrp.Position - root.Position
		
		local newpos = root.Position + (difference.Unit * (difference.Magnitude - 4))
		
		root.Position = newpos
		root.CFrame = CFrame.lookAt(root.Position, humrp.Position)

solution

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.