Moving camera up relative to world space?

I’m trying to make a little “procedural cutscene” where the camera rises up to look down at the player when they die. Although I’m using a custom camera script, it gets disabled when the player dies so it doesn’t conflict with the animations. This line of code is supposed to make the camera rise up into the air:

	ts:Create(cam, TweenInfo.new(20), {CFrame = cam.CFrame * CFrame.new(0, 20, 0)}):Play()

however, it rises relative to the camera, creating weird behaviour like this:

How do I change it from world position and is there a better way to do this entire thing?

2 Likes

cam.CFrame * CFrame.new(0, 20, 0) is camera-relative. You want this instead:

cam.CFrame + Vector3.new(0, 20, 0)

1 Like

Isn’t your CFrame multiplication backwards from what you intend? I mean, don’t you want this:

ts:Create(cam, TweenInfo.new(20), {CFrame = CFrame.new(0, 20, 0) * cam.CFrame}):Play()

or equivalently:

ts:Create(cam, TweenInfo.new(20), {CFrame = cam.CFrame + Vector3.new(0,20,0)}):Play()

Your tween target is 20 studs in the direction of whatever the camera’s UpVector is, and it looks like your camera is tilted (rolled).

1 Like

ts:Create(cam, TweenInfo.new(20), {CFrame = CFrame.new(0, 20, 0) * cam.CFrame}):Play()

I dont believe there is a difference to which operands go where when you multiply CFrames. The camera moving up on local position is the problem. I’m trying to make it go upwards regardless of what orientation the camera is.

Those two do the same thing. The camera still moves up locally and relative to its orientation.

Hmm, nuh uh. Something else in your code is doing that then. From the CFrame documentation:

Huh? This is the updated line I’m using:

ts:Create(cam, TweenInfo.new(20), {CFrame = cam.CFrame + Vector3.new(0, 20, 0)}):Play()

This is what the camera’s properties look like whilst that line of code is running:

It’s still moving up relative to the camera :confused:

EDIT: Nevermind, I fixed it. All I had to do was add this line of code as well:

cam.CameraType = Enum.CameraType.Scriptable

The order absolutely matters, matrix multiplication is not commutative.

Makes some sense. Why would the order matter though? What are the effects of switching the operands around?

Suppose you have a Part that is rotate in some arbitrary way in world space, so that it’s CFrame is already not an identity. In other words, the Part’s Up, Right and LookVectors are not just the world up, right and look directions.

Now, make a CFrame like so:

local rotCF = CFrame.fromOrientation( 0, 0.5 * math.pi, 0)

This is a 90-degree Y-axis rotation. But consider these two expressions:

A) part.CFrame = part.CFrame * rotCF

B) part.CFrame = rotCF * part.CFrame

Option A will rotate the Part around its own UpVector, not around the world Y axis. Furthermore, because rotCF is a pure rotation, the Part.Position will not change.

Option B will rotate the Part around the world Y-axis 90-degrees. And if the part is not at the world origin, its position will also change! If the part is at 100,2,0, a 90-deg world Y-axis rotation will move it to 0,2,-100.

So yeah, very different outcomes. They are only the same if the Part is already at the world origin with identity orientation (all part axes already the same as world axes).

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