AlignOrientation not working properly

In my game, a player can use an ability that allows them to cast a flamethrower. When a player turns their camera quickly, the particle emitters will not match up with a rigid hitbox, so I’m trying to create one using constraints. I’m using AlignPosition and AlignOrientation. The AlignPosition works pretty well connection the joints of the hitboxes, but the AlignOrientation completely messes up for some reason, even with super high Responsiveness/MaxForce/MaxAngularVelocity

Here is a gif:

https://giant.gfycat.com/SomberLoathsomeFlyingfox.webm

Here is the code:
local hb1Size = Vector3.new(4, 4, 10)
local hb2Size = Vector3.new(8, 8, 15)
local hb1CF = sHRP.CFrame * CFrame.new(0, 0, -hb1Size.Z/2)
local hb2CF = hb1CF * CFrame.new(0, 0, -hb2Size.Z/2)
local hb3CF = hb2CF * CFrame.new(0, 0, -hb2Size.Z/2)
--new box part is basically instance new part with automatic cancollide off, anchored true
local hb1 = NewBoxPart()
local hb2 = NewBoxPart()
local hb3 = NewBoxPart()

local ao1, ap1 = Instance.new("AlignOrientation"), Instance.new("AlignPosition")
local ao2, ap2 = Instance.new("AlignOrientation"), Instance.new("AlignPosition")
local ao3, ap3 = Instance.new("AlignOrientation"), Instance.new("AlignPosition")

ao1.Parent = hb1
ap1.Parent = hb1
ao2.Parent = hb2
ap2.Parent = hb2
ao3.Parent = hb3
ap3.Parent = hb3

local a1 = sHRP:FindFirstChild("RootRigAttachment")
local a2, a3 = Instance.new("Attachment"), Instance.new("Attachment")
local a4, a5 = Instance.new("Attachment"), Instance.new("Attachment")
local a6 = Instance.new("Attachment")

a2.Parent = hb1
a3.Parent = hb1
a4.Parent = hb2
a5.Parent = hb2
a6.Parent = hb3

local bruh = 50000000
local bruh2 = 200
local mv = Vector3.new(1, 1, 1) * 50000000

ao1.MaxTorque = bruh
ao2.MaxTorque = bruh
ao3.MaxTorque = bruh

ao1.Responsiveness = bruh2
ao2.Responsiveness = bruh2
ao3.Responsiveness = bruh2

ao1.MaxAngularVelocity = mv * bruh
ao2.MaxAngularVelocity = mv * bruh
ao3.MaxAngularVelocity = mv * bruh

ap1.RigidityEnabled = true
ap2.RigidityEnabled = true
ap3.RigidityEnabled = true

hb1.Size = hb1Size
hb2.Size = hb2Size
hb3.Size = hb2Size

hb1.Massless = true
hb2.Massless = true
hb3.Massless = true

hb1.CFrame = hb1CF
hb2.CFrame = hb2CF
hb3.CFrame = hb3CF

--this is a folder in workspace
hb1.Parent = Effects
hb2.Parent = Effects
hb3.Parent = Effects

a2.Position = Vector3.new(0, 0, hb1Size.Z/2)
a3.Position = Vector3.new(0, 0, -hb1Size.Z/2)
a4.Position = Vector3.new(0, 0, hb2Size.Z/2)
a5.Position = Vector3.new(0, 0, -hb2Size.Z/2)
a6.Position = Vector3.new(0, 0, hb2Size.Z/2)

ap1.Attachment0 = a2
ao1.Attachment0 = a2
ap1.Attachment1 = a1
ao1.Attachment1 = a1

ap2.Attachment0 = a4
ao2.Attachment0 = a4
ap2.Attachment1 = a3
ao2.Attachment1 = a3

ap3.Attachment0 = a6
ao3.Attachment0 = a6
ap3.Attachment1 = a5
ao3.Attachment1 = a5

hb1.Anchored = false
hb2.Anchored = false
hb3.Anchored = false

hb1:SetNetworkOwner(nil)
hb2:SetNetworkOwner(nil)
hb3:SetNetworkOwner(nil)
To help visualize the intended effect

(Bird’s eye view)
ApplicationFrameHost_rdBK9ATbXi

Any help is appreciated, thanks.

3 Likes

Had a look at the video and have a question.
Is the problem that the red boxes are not staying aligned with the floor or that they are not staying aligned with each other?

Look at the boxes, and where the particles are.

The particle emitters are in the correct place and it’s the hitboxes that aren’t moving, correct?

Ok, so viewing the in frame by frame I see at one point the particle emitter and red hit boxes appear to be aligned to each other. After that they don’t.
Can you check the code, or let me see it?
I am asking to confirm there is nothing outside of the repeat that has been changed within the ‘fire’ function (or whatever you are using) that has not been reset back to its original value before executing the function again.

This isn’t my code or problem. I have as much info as you to try and figure this out.

Ooops. Sorry about that. Too eager to help. Should have read your post with more focus.

1 Like

The problem is that the hitboxes are not aligning with the particleemitters, yes.

They should be returning to their original positions (in the direction of the emitters) when the player stops rotating their character. The effect should emulate the drag that particle emitters show. I put some pictures back in OP, hopefully that helps visualize it better

The code I posted is the only thing that influences the hitboxes

Correct

srahc03srahc03srahc03

Silly me forgot HingeConstraints exist. Got it working nice and smooth
https://thumbs.gfycat.com/AntiqueWelltodoBlackbear-mobile.mp4

6 Likes