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 jovborkovic · Mar 26, 2019 at 06:45 PM · scripting problemcamera-movementplayer movement

Camera script for ball not working as intended, looking for some tips, or advise.

New to Unity, just got into it possible 3 days ago and wanted to do a little side project while I was studying to the engine and its libraries.

At the moment however I am stuck and am not really sure how to proceed with this issue I have.

The camera is behaving how I would like it to. Sticking behind the ball like a third person view. Staying in the same y position and allowing viewing with the mouse to look around. However im not able to move forward in the direction the camera is facing.

For Example: I'd be moving forward, but when my camera is facing behind or to the left while holding the W key, it will still be heading in the same direction instead of where the camera is facing. I believe that im supposed to change the transform for the player or something along those lines, but what i've tried hasn't worked for me yet.

I'd love it so much if you guys could let me know what I could be doing wrong with this Camera script.

Comment
Add comment · Show 1
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 jovborkovic · Mar 26, 2019 at 04:52 AM 0
Share
 private const float Y_ANGLE_$$anonymous$$IN = -50.0f;
 private const float Y_ANGLE_$$anonymous$$AX = 50.0f;

 public Transform lookAt;
 public Transform camTransform;

 private Camera cam;

 private float distance = 4.0f;
 private float currentX = 0.0f;
 private float currentY = 0.0f;

 void Start()
 {
     camTransform = transform;
     cam = Camera.main;
 }

 void Update()
 {
     currentX += Input.GetAxis("$$anonymous$$ouse X");
     currentY += Input.GetAxis("$$anonymous$$ouse Y");

     currentY = $$anonymous$$athf.Clamp(currentY, Y_ANGLE_$$anonymous$$IN, Y_ANGLE_$$anonymous$$AX);

     Vector3 dir = new Vector3(0, 3, -distance);
     Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
     camTransform.position = lookAt.position + rotation * dir;
     camTransform.LookAt(lookAt.position);
 }

0 Replies

· Add your reply
  • Sort: 

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

184 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 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

How can I get a Capsule to move and rotate in the direction the cam is facing? 1 Answer

Auto-Scrolling Level - crushing player results in death 0 Answers

Rotate camera around object and let it centered 0 Answers

Simple Third Person Camera-Relative Movement with WASD - kind of working but need a fix 2 Answers

WASD Movement and rotates with mouse 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