I figured out how to do uit
Run script when camera has turned x amount degrees
Greetings everyone.
I'm messing around in Unity and I was wondering if it's possible to run a script when the camera turns 90 degrees in the x or y direction. The player is the parent object and I'm thinking about turning the gravity when the camera rotates
Answer by LLIV · Aug 15, 2016 at 07:03 PM
Yeah that sounds fairly easy. Just attach your script to your camera and make a script. You'll want the transform from the camera. Then look at the localRotation of the Camera. If you detect 90º in either axis trigger your script.
Answer by Aapakaaq · Aug 16, 2016 at 01:02 PM
Thanks LLIV for the reply. An update: I have created the following code in a script for the main camera in the update function
if (Camera.main.transform.localRotation.z > 90) {
Physics2D.gravity = new Vector3(0, 30, 0);
}
But it doesn't seem to work, and I don't know why
You might want to use rotation ins$$anonymous$$d of localRotation.
Follow this Question
Related Questions
CineMachine Freelook - X axis breaks when WorldUpOverride is sideways, any way to fix? 0 Answers
How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers
First person camera snaps when switching cameras 0 Answers
Scene camera aspect ratio and game camera aspect ratio rotated 0 Answers