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