Help with Align Position

So basically, I am working on a combat system like the “Strongest Battleground” and have come across an issue using align Position. When I press the required key to active the (soon to be) ability it is meant to align the attacker with the target, it does achieve this but a bit too well…

robloxapp-20231007-2107326.wmv (1.3 MB)

My goal is to have the attacker and the target face each other and keep about 0.5 studs away when I press the key F (as shown in the script below). I also would apricate some information on how I could make them face each other like this with align orientation.

Here is my code On the Local script:

local Ablity1Event = game:GetService("ReplicatedStorage").RemoteEvents.AblityOneHandlerEvent
local USI = game:GetService("UserInputService")
local CanUseAblity1 = true

function Ablity1Activation(player)
	
	Ablity1Event:FireServer(player)
end

USI.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F and CanUseAblity1 == true then
		Ablity1Activation(player)
	end
end) 

The RayCast Server Script:

local Event = game.ReplicatedStorage.RemoteEvents.AblityOneHandlerEvent
local AblityRange = 5

Event.OnServerEvent:Connect(function(player)
	local attacker = player.Character
	local Character = player.Character
	local HRP = player.Character:FindFirstChild("HumanoidRootPart")

	local rayOrigin = HRP.Position
	local rayDirection = HRP.CFrame.LookVector * AblityRange

	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude


	local raycastResult = workspace:Raycast(rayOrigin, rayDirection)

	if raycastResult then

		if raycastResult.Instance.Parent:FindFirstChild("Humanoid") and raycastResult.Instance.Parent ~= Character then
			--align players readdy for ablity1 animation.
			AblityHandler.AlignPLayers(attacker, raycastResult.Instance.Parent)
			print(raycastResult.Instance.Parent.Name)
		end
	elseif raycastResult == nil then
		--play Failed animation.
	end
end)

The AlbityHandler Module (the one with the align Postion):


function module.AlignPLayers(attacker, target)
	local AlignPosition = Instance.new("AlignPosition", attacker)
	local attachment0 = Instance.new("Attachment", attacker.UpperTorso or attacker.Torso)
	local attachment1 = Instance.new("Attachment",  target.UpperTorso or target.Torso)
	AlignPosition.Name = "Align"
	AlignPosition.Attachment0 = attachment0
	AlignPosition.Attachment1 = attachment1
	AlignPosition.MaxForce = math.huge
	AlignPosition.MaxVelocity = math.huge
	AlignPosition.RigidityEnabled = true
	AlignPosition.ReactionForceEnabled = true
end

return module

(If you have any improvements for my script I would like to know.)

Why not align them manually? That might work.

I need to do it via script because it is only meant to align the player with the other player when a certain key is pressed. Also I am doing this for animating so when I play an animation for both the attacker and target they move with each other

I meant, why not position them manually instead of using an alignposition?

What would I use instead of align position

You’d use CFrames. There is some community tutorials called something along the lines of “how to take 2 players and animate it like a takedown animation” which may help you.

Ok should I use render step to set the players CFrame

No, weld them together. If you can’t find the resource I told you about, tell me.

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