Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 xl_Spenny_lx · May 23 at 01:52 PM · camera-look2 playerfirstperson

How to look left and right with a 2 player controller when up and down is working

I have attempted to create 2 person local game but can only get both players to look up and down, but not left and right. It attempts left and right but to no avail. The first script with the movement and controller are as follows. This is then fed into a second script that is replicated with the unity input system which is the 2nd one

 private float mouseSensitivity = 100f;
 private float xRotation = 0f;
 private Transform playerBody;
 private Vector2 mouseLook;

 [SerializeField]
 private int playerIndex = 0;
 private CharacterController controller;//reference to player controller

 //move
 private float moveSpeed = 3f;
 private Vector3 moveDirection = Vector3.zero;//Vector3(0, 0, 0)passing through 3 axis
 private Vector2 inputVector = Vector2.zero;//Vector2(0, 0, 0)passing through 2 axis - input vectr for movement

 

 private void Awake()
 {
     playerBody = transform.GetChild(1);
     Cursor.lockState = CursorLockMode.Locked;


     controller = GetComponent<CharacterController>();//component for player controller
 }
 
 public void SetInputVector(Vector2 direction)//public method to set direction where we want to move
 {
     inputVector = direction;//inputvector at //Vector3(0, 0, 0) = direction
 }
 
 public void SetInputVectorLook(Vector2 looking)//public method to set direction where we want to move
 {
     xRotation = looking;//inputvector at //Vector3(0, 0, 0) = direction
 }


 public int GetPlayerIndex()
 {
     return playerIndex;
 }


 // Update is called once per frame
 void Update()
 {
     //calculation for movement
     moveDirection = new Vector3(inputVector.x, 0, inputVector.y);
     moveDirection = transform.TransformDirection(moveDirection);
     moveDirection *= moveSpeed;
     controller.Move(moveDirection * Time.deltaTime);//executive movement


     float mouseX = mouseLook.x * mouseSensitivity * Time.deltaTime;
     float mouseY = mouseLook.y * mouseSensitivity * Time.deltaTime;
     xRotation -= mouseY;
     xRotation = Mathf.Clamp(xRotation, -90f, 90);
     playerBody.transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
     playerBody.Rotate(Vector3.up * mouseX);//execute rotation

 }


{}

 private PlayerInput playerInput;
 private Mover mover;


 private void Awake()
 {
     playerInput = GetComponent<PlayerInput>();
     var movers = FindObjectsOfType<Mover>();
     var index = playerInput.playerIndex;
     mover = movers.FirstOrDefault(m => m.GetPlayerIndex() == index);//get mover object for player number
 }
 // Start is called before the first frame update
 void Start()
 {
     
 }

 // Update is called once per frame
 public void OnMove(CallbackContext context)//a method to player input, 
 {
     mover.SetInputVector(context.ReadValue<Vector2>());//set input vector on mover i.e. //read value form mover script
 }
 public void OnLook(CallbackContext context)//a method to player input, 
 {
     mover.SetInputVectorLook(context.ReadValue<Vector2>());//set input vector on mover i.e. //read value form mover script
 }




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

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

186 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

Related Questions

How to clamp horizontal rotation of the camera? 1 Answer

VR : Activate script or animation when the view is looking for an object 0 Answers

Third Person Camera Jittering 0 Answers

CineMachine Camera Movement is inverse 1 Answer

how to make an enemy into a second player 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