Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 LegitTeddyBears · Apr 28, 2017 at 06:02 AM · cameracamera movementinverse

3rd Person Camera inversion

So basically I used the tutorial on https://code.tutsplus.com/tutorials/unity3d-third-person-cameras--mobile-11230 to make my 3rd person camera and it works great but I want the camera to be inverted when I move the mouse up the camera looks down and vice versa. Anyone able to help?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CameraScript : MonoBehaviour {
     //It's the ship
     public GameObject Ship;
 
     public float TurnSpeed;
     //How far away the camera should be from the ship
     private Vector3 offset;
     void Start()
     {
         //May act funny when not maximaized in editor
         //Hides mouse
         Cursor.visible = false;
 
         offset = Ship.transform.position - transform.position;
     }
 
     private void LateUpdate()
     {
         float horizontal = Input.GetAxis("Mouse X") * TurnSpeed;
         Ship.transform.Rotate(0, horizontal, 0);
 
         float desiredAngle = Ship.transform.eulerAngles.y;
         Quaternion rotation = Quaternion.Euler(0, desiredAngle, 0);
         //Take the distance between the camera and the ship
         transform.position = Ship.transform.position - (rotation * offset);
         //Lookat the Ship
         transform.LookAt(Ship.transform);
     }
 }
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
0
Best Answer

Answer by Chris_Payne_QS · Apr 28, 2017 at 09:00 AM

Your question implies that the camera already moves in the vertical axis and you want to invert it, but there's no code here to do that - if so it may be handled by a different script?

But if you're really asking how to ADD that functionality...you basically want to do the same thing with the vertical axis:

      float horizontal = Input.GetAxis("Mouse X") * TurnSpeed;
      float vertical   = Input.GetAxis("Mouse Y") * PitchSpeed;
      Ship.transform.Rotate(vertical, horizontal, 0);
Comment
Add comment · Show 4 · 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 _Keagan · Apr 28, 2017 at 10:26 AM 1
Share

Wouldn't this just swap the X-axis with the Y-axis? I'm pretty sure he just wants to make up down and down up like selecting invert in a shooter game? all you have to do is multiply Y input by -1 say if a bool invert is checked.

avatar image _Keagan · Apr 28, 2017 at 10:29 AM 1
Share

Also why are you rotating the transform of the "ship"? Am I missing something?

avatar image LegitTeddyBears _Keagan · Apr 28, 2017 at 08:14 PM 0
Share

The "Ship" is the player

avatar image LegitTeddyBears · Apr 28, 2017 at 08:15 PM 0
Share

Thank you, i had something on another script similar to this but I removed it thinking it was redundant after replacing it and adding the negative sign it worked perfectly. :)

avatar image
0

Answer by AtGfx · Apr 28, 2017 at 08:24 AM

What about simply take the opposite of your x position ?

 Ship.transform.Rotate(0, -horizontal, 0);
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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera relative rigidbody third person player movement 1 Answer

Why is 2d camera not smooth at 30 FPS 0 Answers

Camera Is glitching when I move 1 Answer

Move the camera in 2D when target reaches bounds. Is there a better way? 0 Answers

Trying to recreate the doodlejump camera c# 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