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 maxiicanowow · Dec 18, 2018 at 01:44 PM · cameracamera-movementcamera rotate

My camera rotates horizontally but not vertically!

So i have this script which only allows my camera to move horizontally, what do i need to add to get it to use the Y axis as well?

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlayerFollow : MonoBehaviour {

 public Transform PlayerTransform;

 private Vector3 _cameraOffset;

 [Range(0.01f, 1.0f)]
 public float SmoothFactor = 0.5f;

 public bool LookAtPlayer = false;

 public bool RotateAroundPlayer = true;

 public float RotationsSpeed = 5.0f;

 void Start () {
     _cameraOffset = transform.position - PlayerTransform.position;    
 }
 
 void LateUpdate () {

     if(RotateAroundPlayer)
     {
         Quaternion camTurnAngle =
             Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationsSpeed, Vector3.up);
     
         _cameraOffset = camTurnAngle * _cameraOffset;
     }

     Vector3 newPos = PlayerTransform.position + _cameraOffset;

     transform.position = Vector3.Slerp(transform.position, newPos, SmoothFactor);

     if (LookAtPlayer || RotateAroundPlayer)
         transform.LookAt(PlayerTransform);
 }

}

thnx in advance!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Zymurer · Dec 18, 2018 at 01:50 PM

I think you need to add a line under this code:

 Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationsSpeed, Vector3.up)

and write this :

 Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * RotationsSpeed, Vector3.left)
 // Or right it depends on you.
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 maxiicanowow · Dec 18, 2018 at 02:15 PM 0
Share

thnx for your reply! but this was the first thing i tried already, yet nothing happens. only horizontal camera movement but nothing vertically .... any further help would be appreciated!!

avatar image Zymurer maxiicanowow · Aug 27, 2019 at 02:43 PM 0
Share

Why don't you make a script to turn your camera by yourself $$anonymous$$aster Indie channel has a toturial about it (if you want to rotate your camera)

Follow this link:https://www.youtube.com/watch?v=3JsuldsGuNw

avatar image
0

Answer by jimmycrazyskills · Dec 18, 2018 at 01:56 PM

Hi mate, I'm not sure if this will help but it might be because in your code you have this line:

 Quaternion camTurnAngle = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationsSpeed, Vector3.up);


On this line you are rotating in relation to Vector3.up, you might need another line to say Rotate on either Vector3.right or Vector3.forward (not sure which is appropriate in your example so try both with the code below)

 camTurnAngle.AngleAxis( Input.GetAxis("Mouse Y") * RotationsSpeed, Vector3.right);

Try adding this line above the _cameraOffset = camTurnAngle * _cameraOffset; line already in your code (P.S I've not tested this so sorry if it's wrong!)

Hope this helped mate :)

Comment
Add comment · Show 1 · 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 maxiicanowow · Dec 18, 2018 at 02:16 PM 0
Share

when i add the line, it doesn't load, something to do with CamTurnAngle it says. i still can't figure out why it doesn't work.

any further help would be appreciated! thnx!

avatar image
0

Answer by maxiicanowow · Dec 18, 2018 at 02:18 PM

Basically i have a third person view, and want to change the camera with my mouse/right joystick around both horizontal and vertical axis.

if someone has a similar code, will you please let me use it?

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

161 People are following this question.

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

Related Questions

Why Do I Have Camera Stutter? 1 Answer

How do I make a camera add torque on two different axis? 0 Answers

How to have free rotation camera? 1 Answer

camera movments fixed.. character controller without using character controller -.-' 2 Answers

How to rotate camera around an object to a certain amount of degrees? 2 Answers


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