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 /
  • Help Room /
avatar image
0
Question by YoloJoe · Jan 30, 2016 at 02:44 PM · playerplayer movementcamera rotatecamera-look

(NEED HELP!) Camera controlled by mouse Y, player controlled by mouse X

Hello everyone.

I am making a third person shooter game and I'm having some trouble creating the camera controls.

I want the camera to be controlled on the Y axis by the mouse moving up and down. I also want the player to rotate on the X axis when I'm moving the mouse Horizontally. Here is what I have done:

CameraMouseLook.js (attatched to the camera)

 function Update ()
 {
 xRotation -= Input.GetAxis("Mouse Y") * lookSensetivity;
 
 xRotation = Mathf.Clamp(xRotation, -60,60);
 
 currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
 
 
 transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
 }

And here is the PlayerMouseLook.js (attached to the player)

 function Update ()
 {
     yRotation += Input.GetAxis("Mouse X") * lookSensetivity;
 
     currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
  
  
     transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
 }

Should I have the camera as a child of the Player? That's what I'm doing now and then I can still rotate the camera along the X axis. If I don't have the camera as a child of the player then the camera is stuck in the starting position and will not follow the player.

I can upload some screenshots or GIFs if you want more details.

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 YoloJoe · Jan 31, 2016 at 11:24 PM 0
Share

Bump. I still need help :(

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by YoloJoe · Jan 30, 2016 at 09:34 PM

Anyone there? I need help :S

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
avatar image
0

Answer by mikii123 · Jan 31, 2016 at 02:12 AM

Code seems good. The camera isn't following the player, because you need to assign the transform.position of it.

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 YoloJoe · Jan 31, 2016 at 02:54 AM 0
Share

In what script? With what code? :P And I guess the camera not should be a child of the player prefab?

avatar image YoloJoe · Feb 01, 2016 at 06:16 AM 0
Share

@mikii123 You There mate? :)

avatar image mikii123 · Feb 01, 2016 at 06:55 AM 0
Share

Unparent the camera object. $$anonymous$$ake it float separately. Than in the script Camera$$anonymous$$ouseLook inside Update add the line:

transform.position = PlayerTransform.position - PlayerTransform.forward * 3;

avatar image YoloJoe mikii123 · Feb 01, 2016 at 04:57 PM 0
Share

It returns an "unknown identifier 'PlayerTransform'" :/

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

45 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

Related Questions

Camera spawn rotate with object 0 Answers

How do I do my camera player look at an specific direction when key pressed 0 Answers

i am tying to build a fps controller from scratch and cant seem to get him to look up or down 0 Answers

Camera to follow one object and rotate towards another 1 Answer

Make Camera follow rotation of 2 Players 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