- Home /
How do i Invert Y axis in this Script?
Hi, i am making a third person game and i recently got a camera script which works like a GTA camera and by the way prevents the camera to pass through walls and objects, but i want to invert its Y axis configuration 'cause when i slide the mouse forward, the camera goes up, and when sliding backward, the camera goes down, and i don't like this way. I´m not exactly a programmer (i focus on the visual things) and i wonder if you could help me doing this. The script has some portuguese words (alvo means target and rotacao means rotation) and here it is(thanks for answering):
using UnityEngine; using System.Collections;
public class collisionCamera : MonoBehaviour {
public Transform alvo;
RaycastHit hit = new RaycastHit();
public float mouseX = 0;
public float mouseY = 0;
public float distCam = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.RotateAround (alvo.position, transform.up, Input.GetAxis ("Mouse X") * mouseX);
transform.RotateAround (alvo.position, transform.right, Input.GetAxis ("Mouse Y") * mouseY);
Vector3 rotacao = transform.eulerAngles;
rotacao.z = 0;
transform.eulerAngles = rotacao;
transform.position = alvo.position - transform.forward * distCam;
if(Physics.Linecast(alvo.position, transform.position, out hit))
transform.position = hit.point+transform.forward*0.4f;
}
}
Answer by unbelievablename · Jun 28, 2015 at 02:42 PM
i want to invert its Y axis configuration 'cause when i slide the mouse forward, the camera goes up, and when sliding backward, the camera goes down, and i don't like this way
Try that code:
transform.RotateAround (alvo.position, transform.right, -Input.GetAxis ("Mouse Y") * mouseY);
Fix me if I wrong.
I know that this is an old thread, but I just wanted to say thank you to @unbelievablename, as I was able to apply this solution to the gamepad input on the game that I'm currently developing, and it also worked for that, so thanks!
Answer by jacobdanielburgess · Aug 17, 2018 at 05:13 PM
use (FlipY ? -1 : 1) , its a great slice of code i found. in your case
public bool FlipY = true;
transform.RotateAround (alvo.position, transform.right, Input.GetAxis ("Mouse Y") * (FlipY ? -1 : 1) );
Your answer
Follow this Question
Related Questions
How can i make my player movement script for a box better? 0 Answers
making models move correctly 1 Answer
Turn on Specific Axis Constraints - Keeping Others Selected (JS) 1 Answer
How to set y rotation axis to 90 on 2d project, always, forever 1 Answer
How To Accelerate/Decelerate Gradually With Torque GetAxis 1 Answer