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 mzaidan1996 · Jul 23, 2020 at 02:10 PM · cameracamera-movementcamera rotatenewbiecamera-look

Would anyone teach me how to create camera movement and look controls?

I need help creating a camera I try replicating what other YouTubers and game developers did for their camera movement but sadly, I didn't have any luck following their tutorials since it changes my movement script. They use add-force while I was using rb.velocity which had smoother movement. Can anyone teach me how to create camera movement and link my camera to my movement so when I look to the right w moves me forward based on the character instead of the world? I hope that made sense because I really don't know how to explain this issue I'm facing. I'm currently new to unity and I've researched quiet a bit about coding but I really cant find my way through this camera movement issue. Thanks and take care every one.

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

Answer by Llama_w_2Ls · Jul 23, 2020 at 02:55 PM

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class MouseComponent : MonoBehaviour
 {
     public float MouseSensitivity = 500f;
 
     public Transform PlayerBody;
 
     float Xrotation = 0f;
 
     //Start is called before the first frame update
     void Start()
     {
         Cursor.lockState = CursorLockMode.Locked;
     }
     
     // Update is called once per frame
     public void Update()
     {
         float MouseX = Input.GetAxis("Mouse X") * MouseSensitivity * Time.deltaTime;
         float MouseY = Input.GetAxis("Mouse Y") * MouseSensitivity * Time.deltaTime;
 
         Xrotation -= MouseY;
         Xrotation = Mathf.Clamp(Xrotation, -90f, 90f);
 
         transform.localRotation = Quaternion.Euler(Xrotation, 0f, 0f);
 
         PlayerBody.Rotate(Vector3.up * MouseX);
     }
 }

From the Brackeys tutorial lol. Should help with what youre asking.

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 Llama_w_2Ls · Jul 23, 2020 at 02:55 PM 0
Share

Attach the script to your main camera, thats it

avatar image
0

Answer by mzaidan1996 · Jul 23, 2020 at 02:57 PM

just tried it and it is not working. @Llama_w_2Ls

Comment
Add comment · Show 26 · 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 Llama_w_2Ls · Jul 23, 2020 at 03:02 PM 0
Share

What exactly is not working. When you move your mouse, is the camera not moving with it?

avatar image Llama_w_2Ls · Jul 23, 2020 at 03:08 PM 0
Share

You also need to assign the playerbody, which is the GameObject that your character controller is sitting under

avatar image mzaidan1996 Llama_w_2Ls · Jul 23, 2020 at 03:09 PM 0
Share

I tried it but my camera isnt moving, I changed my mouse sensitivity and I put my player body but no movement showed and nothing happened.

avatar image mzaidan1996 mzaidan1996 · Jul 23, 2020 at 03:14 PM 0
Share

Ok im using a new script this is it using UnityEngine;

public class CameraControl : $$anonymous$$onoBehaviour { //These are the variables that are associated with the camera looking speed. public float mouseSensitivity; public float mouseSmoothing;

 private Vector2 currentlookingPos;
 private Vector2 smoothedVelocity;
 private GameObject player;


 private void Start()
 {
     player = transform.parent.gameObject;
     //This is to lock and make the cursor invisible when playing the game.
     Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
     Cursor.visible = false;
 }
 private void Update()
 {
     $$anonymous$$ouseControl();
 }
 private void $$anonymous$$ouseControl()
 {
     Vector2 inputValues = new Vector2(Input.GetAxisRaw("$$anonymous$$ouse X"), Input.GetAxisRaw("$$anonymous$$ouse Y"));
     float mouseX = Input.GetAxisRaw("$$anonymous$$ouse X") * mouseSensitivity * mouseSmoothing;
     float mouseY = Input.GetAxisRaw("$$anonymous$$ouse Y") * mouseSensitivity * mouseSmoothing;

     inputValues = Vector2.Scale(inputValues, new Vector2(mouseSensitivity * mouseSmoothing, mouseSensitivity * mouseSmoothing));

     smoothedVelocity.x = $$anonymous$$athf.Lerp(smoothedVelocity.x, inputValues.x, 1f / mouseSmoothing);
     smoothedVelocity.y = $$anonymous$$athf.Lerp(smoothedVelocity.y, inputValues.y, 1f / mouseSmoothing);

     currentlookingPos += smoothedVelocity;
     transform.localRotation = Quaternion.AngleAxis(-currentlookingPos.y, Vector3.right);
     player.transform.localRotation = Quaternion.AngleAxis(currentlookingPos.x, player.transform.up);

     currentlookingPos.y = $$anonymous$$athf.Clamp(currentlookingPos.y, -90f, 90f);
 }

} but for some weird reason, when I look at a certain side and press w, it keeps taking me to another spot, for example, i spawn and hold W and it is moving me forward, when i look to the left, and i press w, it takes me to the right. my movement script uses rb.velocity = new vector3(x, rb.velocity.y, z) * walkspeed.

Thanks for the help @Llama_w_2Ls .

Show more comments

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

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

Jerky 3rd Person Camera Following Movement and Rotation 0 Answers

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

Rotate Camera to the object 0 Answers

How to have free rotation camera? 1 Answer

Free Orbit Cam and Mouse Aim Cam aren't working together 0 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