The issue has changed since the initial post, see the bottom of the list of replies for the new issue.
It’s me once again with yet another probably arbitrary question on how CFrame
works because this stuff is very confusing.
Straight to the point yet again:
I’m making a punching attack for the aforementioned boss fight. It’s supposed to fire it’s fists towards the nearest player based on the boss’s HumanoidRootPart Rotation
, Raycasting
from the top of the fists and Tweens
.
As you can tell, it doesn’t work quite right otherwise I wouldn’t be making this post.
When I print the values for the Raycasts
along with a few other bits of the code ( which of course will be below ), I get some very odd positional values which are nowhere close to where the boss actually is.
The code:
local LeftArmClone = game.ServerStorage.LeftArmPunchingClone:Clone()
local RightArmClone = game.ServerStorage.RightArmPunchingClone:Clone()
LeftArmClone.Parent = workspace
RightArmClone.Parent = workspace
LeftArmClone.CFrame = ActualLeftArm.CFrame * CFrame.Angles(math.rad(180),0,0)
RightArmClone.CFrame = ActualRightArm.CFrame * CFrame.Angles(math.rad(180),0,0)
local RayCastParamsVariable = RaycastParams.new()
RayCastParamsVariable.FilterType = Enum.RaycastFilterType.Blacklist
local ParentDecendants = Boss:GetDescendants()
local LeftArmDescendants = LeftArmClone:GetDescendants()
local RightArmDescendants = RightArmClone:GetDescendants()
RayCastParamsVariable.FilterDescendantsInstances = {ParentDecendants, LeftArmDescendants, RightArmDescendants}
local RayCast1 = Ray.new(LeftArmClone.Position, LeftArmClone.CFrame.UpVector * 300)
local RayCast2 = Ray.new(RightArmClone.Position, RightArmClone.CFrame.UpVector * 300)
local RayCastResult1 = workspace:Raycast(RayCast1.Origin, RayCast1.Direction, RayCastParamsVariable)
local RayCastResult2 = workspace:Raycast(RayCast2.Origin, RayCast2.Direction, RayCastParamsVariable)
local Distance1 = (LeftArmClone.Position - RayCastResult1.Position).Magnitude
local Distance2 = (RightArmClone.Position - RayCastResult2.Position).Magnitude
local Timer1 = (Distance1 / 0.5) / 100
local Timer2 = (Distance2 / 0.5) / 100
local TweenInf1 = TweenInfo.new(Timer1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local Finish1 = {CFrame = CFrame.new(LeftArmClone.CFrame.UpVector * Distance1)}
local Tween1 = TweenS:Create(LeftArmClone, TweenInf1, Finish1)
local TweenInf2 = TweenInfo.new(Timer2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local Finish2 = {CFrame = CFrame.new(RightArmClone.CFrame.UpVector * Distance2)}
local Tween2 = TweenS:Create(RightArmClone, TweenInf2, Finish2)
Tween1:Play()
Tween2:Play()
Now here’s an explanation of the weird bits incase it helps anyone along with extra info.
The Raycast Params
( should ) take the boss’s model as well as both of the punching arms, get their descendants, then blacklist them so they cannot be hit with a potential Raycast
from the arms and possibly mess it up.
The Tweens
that actually move it times the UpVector by a distance amount as the UpVector * [positive number] =
movement in the direction of the top of the fists, or in other words, forward in a downwards direction due to how they are initially rotated. ( at least that is the intention )
Extra bits of info:
the boss arena is a large cylinder with a hole punched right through it, it uses the CollisionFidelity
setting PreciseConvexDecomposition
for reference.
the arms must be moved and rotated with CFrame
as there are Welded
parts on the model and using Orientation / Position
would mess it up.
TLDR: a very large mess of Raycasting
and CFrame
tweens needs resolving