Camera lookvector with attachments

  1. What do you want to achieve?
    I’m trying to make a camera that hovers above the player’s left side, and aims where the camera is looking. There’s only one issue: It appears to roll when it should be pitching.

  2. What is the issue?
    The issue, as described above, is that the camera ball rolls instead of pitches. See attached video.

  3. What solutions have you tried so far?
    I’ve tried adjusting a ton of different parameters to get to this point; but I can’t seem to figure out how to swap 2 rotations…

Code that I have so far:

Backpack.Flashlight.AttemptSync.OnServerEvent:Connect(function(player: Player,lookVec:Vector3)
	if player.Character ~= C then return end -- though this shouldn't happen
	assert(typeof(lookVec) == "Vector3","Input must be a V3.")
	local CF = CFrame.new(Vector3.zero,lookVec)*CFrame.Angles(0,math.rad(90),0)
	local characterCF = C:GetPivot()-C:GetPivot().Position
	Backpack.O2Tank.Pivot.RotatePivot.CFrame = characterCF:ToObjectSpace(CF) + Vector3.new(0.911, 1.7, -2.026)
end)

Any help with this would be welcomed. This is kinda driving me nuts. [and yes the flashlight is not supposed to be looking at the camera but I inverted the 90 for the purpose of that video so you can see what it was doing]

2 Likes

a much much simpler way of doing this is to get the position of the camera and then point the ball to it like so:

ball.CFrame = CFrame.new(ball.Position, camera.Position)

this will make it point to the camera

2 Likes

It’ll point to the camera, not where the camera is facing.

What I want to have happen is the camera light will point in the direction where the camera is facing so that the player can see where they’re looking, in both water and air.

The problem I’m having is that, while I’m using attachments, I get one of the following:

  • Rotation is on the wrong axis when pivoting, or
  • Rotation is completely wrong

I’m trying to find the best way to do it so that other people know where the client is looking. I may have to resort to setting the local CFrame first, getting the position in world, then setting the world CFrame to what I need it to be. I’d prefer to not do this because that’s multiple different property sets which could cause issues with performance since it’s the serverside that has to set the positions, not client-side.

Code that I have so far:

turns out the solution was right in front of my nose.

I was rotating the look CFrame, not the parent CFrame, which was causing… This weirdness. I hate working with CFrames.

The solution was to modify the characterCF by rotating it by 90, not the camera CF that it generates using the lookVector.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.