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.)