# Camera turns 180 degrees but also in opposite way of their look vector

Hi,

This is kind of hard to explain but, I want to turn the camera 180 degrees, but I don’t want them to look the opposite way. This is how it looks going opposite:

https://gyazo.com/0dbb52088b073e276c78cf5b0ec8d162

How do I fix this?

Line:

``````CurrentCamera.CFrame = CFrame.Angles(0, math.rad(180), 0) * CurrentCamera.CFrame -- 180 deg
``````
1 Like

So you want to rotate only the character and not the camera?

1 Like

Well, the camera rotates the character already, because of shiftlock.

Here’s a sketch of where I want the camera to look

Blue = Where I want it to go
Red = Where it’s current going right now (opposite)
Light Blue = Player’s original cframe

Sorry, it’s kind of hard to put into words.

i’m still struggling with this…

So you want it to turn an approximate of 90 degrees instead of 180?

Instead of 180°, you rotate by -(2x the angle) you entered in.

If I do 90 degrees it doesn’t turn the player backwards. Here’s how it looks like:

``````CurrentCamera.CFrame = CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0) * CurrentCamera.CFrame
``````

https://gyazo.com/2573dc78396407e2e2483763fe193781

What do you mean by -2x the angle? Can you show me.

If you enter a wall 45°, you bounce off -(2 * 45)°, which is -90°, the negative is there to supply the LookVector, might not supposed to be there.

Entering a wall 25°, you bounce off -(2 * 25)°, which is -50°.

Another equivalent method of this is just bouncing, from the wall’s LookVector, -(angle of entry).
Enter -45°, exit 45°.
Enter 67°, exit -67°.

This is supposedly how light bounces off reflective surfaces.

1 Like

I don’t think I did this right:

https://gyazo.com/281e2f113dc14332f0f296091d6c6d82

``````local velocity = Root.CFrame:Inverse() * (Root.Position + Root.AssemblyLinearVelocity)
local yDirection = math.atan2(velocity.X, -velocity.Z)
local roundedDirection = math.ceil(math.deg(yDirection) - 0.5)

print(roundedDirection, -(2 * roundedDirection))
CurrentCamera.CFrame = CFrame.fromEulerAnglesXYZ(0, -(2 * roundedDirection) , 0) * CurrentCamera.CFrame -- 180 deg
``````

This is what I tried to do

Last two lines try removing the unary operator (negative), I’ve never attempted to script something like this so maybe. Oh and maybe check if the angle is 0° and instead set roundedDirection to 90°.

``````local velocity = Root.CFrame:Inverse() * (Root.Position + Root.AssemblyLinearVelocity)
local yDirection = math.atan2(velocity.X, -velocity.Z)
local roundedDirection = math.ceil(math.deg(yDirection) - 0.5)

local reflectedDirection = (2 * roundedDirection)
print(roundedDirection, reflectedDirection)

CurrentCamera.CFrame = CFrame.fromEulerAnglesXYZ(0, reflectedDirection , 0) * CurrentCamera.CFrame
``````

It only works sometimes + when the angle is 0, it doesn’t turn u around.

Maybe:

``````local velocity = Root.CFrame:Inverse() * (Root.Position + Root.AssemblyLinearVelocity)
local yDirection = math.atan2(velocity.X, -velocity.Z)
local roundedDirection = math.ceil(math.deg(yDirection) - 0.5)

local reflectedDirection = (180 - (2 * roundedDirection))
print(roundedDirection, reflectedDirection)

CurrentCamera.CFrame = CFrame.fromEulerAnglesXYZ(0, reflectedDirection , 0) * CurrentCamera.CFrame``````
1 Like

It did yield better results but it sometimes barely turns you.

https://gyazo.com/dc24b3778bb3aeb365345214ff1989e6

Hm.

``````local velocity = Root.CFrame:Inverse() * (Root.Position + Root.AssemblyLinearVelocity)
local yDirection = math.atan2(velocity.X, -velocity.Z)
local roundedDirection = math.ceil(math.deg(yDirection) - 0.5)

local reflectedDirection = (((2 * roundedDirection) > 180 and 360 or 180) - (2 * roundedDirection))
print(roundedDirection, reflectedDirection)

CurrentCamera.CFrame = CFrame.fromEulerAnglesXYZ(0, reflectedDirection , 0) * CurrentCamera.CFrame``````
1 Like

More better results but it’s still kind of weird:

https://gyazo.com/d18d70e619d6988bce2317f85d87495b

you can take a look for your self here:

I’m kind of stuck with method 2, I tried method 1 again but instead I did this:

``````local x, y, z = CurrentCamera.CFrame:ToEulerAnglesXYZ()
local yRounded = math.ceil(math.deg(y) - 0.5)

local reflectedDirection = (((2 * yRounded) > 180 and 360 or 180) - (2 * yRounded))

print(yRounded, reflectedDirection)

CurrentCamera.CFrame = CFrame.fromEulerAnglesXYZ(0, reflectedDirection , 0) * CurrentCamera.CFrame
``````

Same results

Maybe you could try rotating the character along with the camera. Maybe the character doesn’t update orientation in line with the script?