Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by alexd_tmp · Jun 28, 2015 at 12:09 PM · scripting problemaxisthird-person-camera

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;
         
         
     }
 }  
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image alexd_tmp · Jun 28, 2015 at 05:58 PM 0
Share

That works great!! thanks a lot

avatar image John_Vella · Jan 18, 2018 at 05:19 PM 0
Share

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!

avatar image
0

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) );


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges