Barrelroll, freeze camera.

Hello everyone,

I want to get roll effect like in this video (1:38)

The problem is in camera. It’s rotating with my spaceship. How can i make my camera stay in one place until rolling effect ends?

Is the camera a “child” of your spaceship gameobject? If it is, you might have to “un-parent” it and write some custom code to have the camera follow your spaceship in a certain way, because child objects always take on the position and rotation of their parent objects. That makes it difficult to reverse that behavior. This way, you can rotate it independently of your spaceship if you want to.

If the camera is not a child object, then you’ll have to code your camera as I said above.

Some pseudo code for that would be like:

In the update function of a script you attach to your spaceship you do something like:
Camera.main.transform.position = mySpaceShipGameObject.transform.position + Vector3(-5, 5, 0); (or whatever vector places the camera behind your spaceship and maybe up a ways).

For rotation you could match your spaceship’s rotation, until your spaceship does something special. So to match it’s
rotation you simply do:

if(notDoingBarrellRoll) {
   Camera.main.transform.rotation = mySpaceShipGameObject.transform.rotation;
}
else {
   //We're doing a barrell roll now so set the camera's rotation to specific rotation
   Camera.main.transform.rotation = theCamerasFreezeRotation;
}

*Note that in that psuedo code I have a boolean variable for a condition check and “theCamerasFreezeRotation” is a rotation that you have to define or specify.

Once you have your camera following your spaceship independently, it makes it much easier to do whatever you want with it.

1 Like

It’s working but… I’m using my mouse to rotate camera too. I’m using this code:

transform.Rotate(Input.GetAxis("Mouse Y")/2, 0, -Input.GetAxis("Mouse X")/2);

So, when i’m rotating Left/Right everything is fine but when going Up/Down, camera is reacting “faster” or something like that. I made this video to show it what is going on.

Ya that will interfere with your rotation and make it move faster or slower probably.

I’m not too good with input axis stuff, but maybe try placing your input axis code in a condition check as well. For example, something like:

if(notDoingBarrellRoll) {
   Camera.main.transform.rotation = mySpaceShipGameObject.transform.rotation;

    transform.Rotate(Input.GetAxis("Mouse Y")/2, 0, -Input.GetAxis("Mouse X")/2);
}
else {
   //We're doing a barrell roll now so set the camera's rotation to specific rotation
   Camera.main.transform.rotation = theCamerasFreezeRotation;
}

Overall though, someone else might have to help you with that, I don’t work with inputs that much sorry.

1 Like

It’s not working. Thanks for help anyway. I’ll wait for someone that can help.