Need Help With Implementing Idea

So, basically, I’m trying to get the camera and player to work correctly. The game starts out as a normal looking 2D game. but when you press the ‘R’ key, the camera rotates, which gives you a different view of the ground platform. The player is supposed to always be facing the camera, since it’s rotation is always set to the camera’s rotation. The problem is that it only faces the camera when the ‘R’ key is being pressed. When the key is not being pressed it either reverts back to it’s original rotation, or it stays in the rotation changed by the camera until you move. That’s also another problem. The player is supposed to go left and right when the ‘LEFT’ and ‘RIGHT’ arrow keys are pressed. It works, but when theplayer rotates, it still goes in the default right and left direction, meaning it goes back to facing the front (the rotation is set to 0, 0, 0). So I need a way to make sure that when you move right, it’s the right relative to the camera’s rotation, not the player’s position. I know this is kinda long, and might be hard to understand, but how do I implement these concepts?

Link To Editor:
Link To Script:

Do you always want the player to be facing the camera or only if R is held down? Right now, the code you have written has the player rotation only changed when R is pressed.

1 Like

I always want the player facing the camera.

In which case, why is the code for facing the camera in the if statement for checking if the R key is pressed?

I want the code to only rotate the camera when the ‘R’ key is pressed, but I want the effects to go on after the ‘R’ key was pressed.

So ther R key have to switch a variable from 0 to 1 and when that variable is 1 in the update function the rotate camera code is executed.

Ah, now I see the issue.

As the player is a rigidbody, you cannot/shouldn’t set the rotation directly on the entity object as it is overridden by the physics engine internal simulation. This makes it a little awkward.

In this case, as the collision is a uniform box, you can separate the visual representation from the physics object which will work in this case. The visual representation can always face the camera in this case while the rigidbody is unaffected.

Here’s an example:

1 Like

I tried to implement it, but it didn’t work. It doesn’t show any errors, but the model isn’t rotating. Did I do something wrong, or is this an engine glitch?