Attachment cant rotate along the Y axis

I want to make a dashing system that moves the player in their camera’s direction, but when i try to set an attatchments rotation to math the camera’s, instead of looking at the cameras up direction. it just changes the SecondaryAxis to always keep it flat

DashAttachment.WorldCFrame = CFrame.new(DashAttachment.WorldPosition, DashAttachment.WorldPosition + cameraDirection)
DashAttachment.Orientation += Vector3.new(0,90,0)

1 Like

Well, that’s because you’re adding orientation to the cframe that is already pointing in the right direction.

Just as a general rule of thumb, don’t use the Orientation or Rotation properties, they don’t work intuitively. Just use CFrames instead.

As per your problem tho, remove the Orientation part, and just change the cameraDirection variable to be Camera.CFrame.UpVector instead of Camera.CFrame.LookVector if you want the camera’s up direction.

2 Likes

idk if im reading your reply wrong, but my problem is not that it moves on the z axis, but that it ONLY moves on the z axis, also im adding 90 because in my experience attatchemnents are always offset by 90

1 Like

Okay let me get this straight, do you want the attachment to look exactly in the direction the camera is looking in? Or the upvector of the camera? Or are you looking for something completely different?
I don’t quite get what you mean by moving it, since you only seem to be trying to rotate it.

2 Likes

exactly the cameras lookvector, sorry for the confusion

1 Like

I mean yeah, in that case what you’re looking for is what I told you, so smth like this.

DashAttachment.WorldCFrame = CFrame.new(DashAttachment.WorldPosition, DashAttachment.WorldPosition + cameta.CFrame.LookVector)

No need for the orientation change.

1 Like

I will also add on that the secondary axis and primary axis do not represent the look vector.

They only represent the right vector and up vector, the look vector is derived from the cross product of those two.

You can test this by putting an attachment into a new part at 0,0,0 orientation.

So this means in attachment view the arrows will never be pointing along the lookvector and will look weird but its expected.

removing the orientation addition js makes it move the wrong way, also thats literally the same code

i know, but i js wna get it to look upwards

1 Like

Could this help? This is in a LocalScript in StarterCharacterScripts:

local char = script.Parent
task.wait(1)
local cam = workspace.CurrentCamera
local hum = char.Humanoid
local hrp = char.HumanoidRootPart
local att = Instance.new("Attachment", hrp)
local vectorForce = Instance.new("VectorForce", hrp)
vectorForce.Attachment0 = att
vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World -- Important
vectorForce.ApplyAtCenterOfMass = true

task.spawn(function()
	while task.wait() do
		--att.WorldCFrame = CFrame.lookAt(hrp.Position, hrp.Position + cam.CFrame.LookVector) -- Not necessary
		vectorForce.Force = cam.CFrame.LookVector*20000
	end
end)
1 Like

i know this could and prolly does work, but i asked abt attachments, sorry

Can you send more of the code? I’d like to help, but I don’t have much to go off of except that an attachment is not looking up when you look up, which works if you just do this:

local char = script.Parent
task.wait(1)
local cam = workspace.CurrentCamera
local hum = char.Humanoid
local hrp = char.HumanoidRootPart
local att = Instance.new("Attachment", hrp)

task.spawn(function()
	while task.wait() do
		att.WorldCFrame = CFrame.lookAt(hrp.Position, hrp.Position + cam.CFrame.LookVector)
	end
end)

so I’m probably missing something here.

thats exactly what im doing, cameradirection is the lookvector

I’m saying that code works fine for me. You do not have that exact same code if it doesn’t work for you, so I’d like to see the entirety of the code you have in order to help. I’m talking about more than just those two lines you shared in the OP.

Server
local Services = require(game:GetService("ReplicatedStorage").Modules.ServicesModule)

local Remote: RemoteEvent = Services.ReplicatedStorage.Remotes.DashRemote

Remote.OnServerEvent:Connect(function(Player: Player, cameraDirection: Vector3, Enabled: boolean)
	local Character: Model? = Player.Character
	local Humanoid: Humanoid = Character:FindFirstChildOfClass("Humanoid")
	local RootPart: BasePart? = Humanoid.RootPart
	local DashAttachment: Attachment = RootPart:WaitForChild("DashAttachment")
	local DashVelocity: LinearVelocity = RootPart:WaitForChild("DashVelocity")
	
	if Enabled == true then
		DashVelocity.Parent = RootPart
		DashVelocity.Attachment0 = DashAttachment
		DashAttachment.WorldCFrame = CFrame.new(DashAttachment.WorldPosition, DashAttachment.WorldPosition + cameraDirection)
		DashAttachment.Orientation += Vector3.new(0,90,0)
		DashVelocity.Enabled = true
	elseif Enabled == false then
		DashVelocity.Enabled = false
	elseif Enabled == nil then
		DashAttachment.WorldCFrame = CFrame.new(DashAttachment.WorldPosition, DashAttachment.WorldPosition + cameraDirection)
		DashAttachment.Orientation += Vector3.new(0,90,0)
	end
	
	Remote:FireAllClients(Character, inputState)
end)

Client
local function FireDashRemote()
	local cameraDirection = Services.Workspace.CurrentCamera.CFrame.LookVector
	Services.ReplicatedStorage.Remotes.DashRemote:FireServer(cameraDirection, nil)
end

local function Dash(actionName: string, inputState: Enum.UserInputState, _inputObject: InputObject)
	if actionName == "Dash" then
		if inputState == Enum.UserInputState.Begin then
			if script:GetAttribute("DashEnabled") == false then
				script:SetAttribute("DashEnabled", true)
			end
			--Services.RunService:BindToRenderStep("FireDashRemote", Enum.RenderPriority.Character.Value, FireDashRemote)
		elseif inputState == Enum.UserInputState.End then
			if script:GetAttribute("DashEnabled") == true then
				script:SetAttribute("DashEnabled", false)
			end
			--Services.RunService:UnbindFromRenderStep("FireDashRemote")
			--Services.ReplicatedStorage.Remotes.DashRemote:FireServer(cameraDirection, Enum.UserInputState.End)
		end
	end
end

script:GetAttributeChangedSignal("DashEnabled"):Connect(function(...: any) 
	local cameraDirection = Services.Workspace.CurrentCamera.CFrame.LookVector
	if script:GetAttribute("DashEnabled") == true then
		Services.RunService:BindToRenderStep("FireDashRemote", Enum.RenderPriority.Character.Value, FireDashRemote)
	else
		Services.RunService:UnbindFromRenderStep("FireDashRemote")
		Services.ReplicatedStorage.Remotes.DashRemote:FireServer(cameraDirection, script:GetAttribute("DashEnabled"))
	end
	Services.ReplicatedStorage.Remotes.DashRemote:FireServer(Services.Workspace.CurrentCamera.CFrame.LookVector, script:GetAttribute("DashEnabled"))
end)

Services.ContextActionService:BindAction("Dash", Dash, true, Enum.KeyCode.Q)

1 Like

This works (assuming you’re using a VectorForce for the force). All I did was remove the orientation changes on the server:

local Remote: RemoteEvent = script.Parent.RemoteEvent

Remote.OnServerEvent:Connect(function(Player: Player, cameraDirection: Vector3, Enabled: boolean)
	local Character: Model? = Player.Character
	local Humanoid: Humanoid = Character:FindFirstChildOfClass("Humanoid")
	local RootPart: BasePart? = Humanoid.RootPart
	local DashAttachment: Attachment = RootPart:FindFirstChild("DashAttachment")
	local DashVelocity: LinearVelocity = RootPart:FindFirstChild("DashVelocity")
	
	if not DashAttachment then
		DashAttachment = Instance.new("Attachment")
		DashAttachment.Name = "DashAttachment"
		DashAttachment.Parent = RootPart
	end
	
	if not DashVelocity then
		DashVelocity = Instance.new("VectorForce") :: VectorForce
		DashVelocity.Name = "DashVelocity"
		DashVelocity.Force = Vector3.new(0, 0, -10000)
		DashVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
		DashVelocity.Parent = RootPart
	end
	
	if Enabled == true then
		DashVelocity.Parent = RootPart
		DashVelocity.Attachment0 = DashAttachment
		DashAttachment.WorldCFrame = CFrame.new(DashAttachment.WorldPosition, DashAttachment.WorldPosition + cameraDirection)
		--DashAttachment.Orientation += Vector3.new(0,90,0)
		DashVelocity.Enabled = true
	elseif Enabled == false then
		DashVelocity.Enabled = false
	elseif Enabled == nil then
		DashAttachment.WorldCFrame = CFrame.new(DashAttachment.WorldPosition, DashAttachment.WorldPosition + cameraDirection)
		--DashAttachment.Orientation += Vector3.new(0,90,0)
	end

	--Remote:FireAllClients(Character, inputState)
end)
1 Like

im using a linear velocity, how are they that different

LinearVelocity version works too:

local Remote: RemoteEvent = script.Parent.RemoteEvent

Remote.OnServerEvent:Connect(function(Player: Player, cameraDirection: Vector3, Enabled: boolean)
	local Character: Model? = Player.Character
	local Humanoid: Humanoid = Character:FindFirstChildOfClass("Humanoid")
	local RootPart: BasePart? = Humanoid.RootPart
	local DashAttachment: Attachment = RootPart:FindFirstChild("DashAttachment")
	local DashVelocity: LinearVelocity = RootPart:FindFirstChild("DashVelocity")
	
	if not DashAttachment then
		DashAttachment = Instance.new("Attachment")
		DashAttachment.Name = "DashAttachment"
		DashAttachment.Parent = RootPart
	end
	
	if not DashVelocity then
		DashVelocity = Instance.new("LinearVelocity")
		DashVelocity.Name = "DashVelocity"
		DashVelocity.VectorVelocity = Vector3.new(0, 0, -10)
		DashVelocity.MaxForce = 1000000000
		DashVelocity.Attachment0 = DashAttachment
		DashVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
		DashVelocity.Parent = RootPart
	end
	
	if Enabled == true then
		DashVelocity.Parent = RootPart
		DashVelocity.Attachment0 = DashAttachment
		DashAttachment.WorldCFrame = CFrame.new(DashAttachment.WorldPosition, DashAttachment.WorldPosition + cameraDirection)
		--DashAttachment.Orientation += Vector3.new(0,90,0)
		DashVelocity.Enabled = true
	elseif Enabled == false then
		DashVelocity.Enabled = false
	elseif Enabled == nil then
		DashAttachment.WorldCFrame = CFrame.new(DashAttachment.WorldPosition, DashAttachment.WorldPosition + cameraDirection)
		--DashAttachment.Orientation += Vector3.new(0,90,0)
	end

	--Remote:FireAllClients(Character, inputState)
end)
1 Like

thank you, i have no idea why it didnt work in the first place tho

1 Like

its cuz it was line, not vector, which is weird