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 /
avatar image
0
Question by SFT_Games · Jun 02, 2021 at 04:20 AM · camera-lookinputmanager

3rd person camera problems

I'm in need of some help. I've been trying to get this 3rd person camera to rotate using the mouse. It isn't working,

I'm showing two different classes

This one is the camera follower: using UnityEngine; using UnityEngine.InputSystem;

public class CameraFollower : MonoBehaviour { [Header("Target")]

 [Tooltip("Gameobject you want the camera to follow.")]
 public GameObject target = null;

 [Tooltip("  Speed for lerping - the less of this\nvalue, the faster the snap.")]
 public float posCamSpeed = 0.125f;

 [Tooltip("  Speed for rotating - the more of this\nvalue, the faster the snap.")]
 public float rotCamSpeed = 0.125f;

 [SerializeField, Tooltip("Offset for 3rd person")]
 private Vector3 offset = new Vector3(0f, 0f, 0f);

 private float cInputX;
 private float cInputY;

 private Vector2 CamInputRotation;
 private void Start()
 {
 }
 
 
 

 // LateUpdate is called after all Updates - this is to take into account all character movement
 void LateUpdate()
 {
     CamInputRotation = target.GetComponent<PlayerMovement>().cameraInput;

     //Splits
     cInputX = cInputX + CamInputRotation.x;
     cInputY = cInputY + CamInputRotation.y;


     Vector3 desiredPosition = target.transform.position + offset;
     Vector3 TargetsPosition = target.transform.position;

     

     transform.position = Vector3.Slerp(transform.position, desiredPosition, posCamSpeed);

     transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(TargetsPosition - transform.position + new Vector3(cInputX, cInputY, 0f)), rotCamSpeed * Time.deltaTime);
     Debug.Log(CamInputRotation);
 }

}

And this one is the PlayerMovement script

using UnityEngine; using UnityEngine.InputSystem;

[RequireComponent(typeof (Rigidbody))] public class PlayerMovement : MonoBehaviour { private Rigidbody controller; private Vector3 playerVelocity; private bool groundedPlayer;

 [SerializeField]
 private float playerSpeed = 2.0f;
 [SerializeField]
 private float jumpHeight = 1.0f;
 [SerializeField] 
 private float gravityValue = -9.81f;

 private Vector2 movementInput = Vector2.zero;
 private bool jumped = false;

 public Vector2 cameraInput = Vector2.zero;

 private void Start()
 {
     controller = gameObject.GetComponent<Rigidbody>();
 }

 public void OnMove(InputAction.CallbackContext context)
 {
     movementInput = context.ReadValue<Vector2>();
 }

 public void OnJump(InputAction.CallbackContext context)
 {
     jumped = context.action.triggered;
 }

 public void OnLooking(InputAction.CallbackContext context)
 {
     cameraInput = context.ReadValue<Vector2>();
 }

 public void OnCollisionStay(Collision collision)
 {
     if (collision.collider.tag == "Ground")
     {
         groundedPlayer = true;
     }
     else groundedPlayer = false;
 }

 void Update()
 {
     
     //if (groundedPlayer && playerVelocity.y < 0)
     //{
     //    playerVelocity.y = 0f;
     //}

     Vector3 move = new Vector3(movementInput.x, 0, movementInput.y);
     controller.AddForce(move * Time.deltaTime * playerSpeed, ForceMode.Impulse);

     //if (move != Vector3.zero)
     //{
     //    gameObject.transform.forward = move;
     //}

     // Changes the height position of the player..
     if (jumped && groundedPlayer)
     {
         playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
     }

     //playerVelocity.y += gravityValue * Time.deltaTime;
     //controller.Move(playerVelocity * Time.deltaTime);
     //Debug.Log(cameraInput);
 }

}

I do hope someone arrives soon.

Anyway, I debugged the cameraInput variable from the PlayerMovement script. I'm not sure why, but it's not showing any input being made, no matter how fast I move my mouse. I checked the Input Action Map, and everything's set up right (Pass Through - Vector2 - Mouse (Delta).


I'm just not sure what's wrong with this?

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 chubshobe · Jun 02, 2021 at 10:10 AM 0
Share

Please clean up the code and post only the relevant parts. It would make solving the problem much easier and quicker. The only relevant piece of information here is that you weren't able to get mouse input from the new input manager. Next step would be to show relevant information about that, like the input actions, the input component, reading and storing the input.

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

121 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

Related Questions

Change input from mouse to game pad 1 Answer

Mac version mouse lock not working properly 1 Answer

Adding some recoil to the Camera (FPS) 1 Answer

Dedicated Cameras? 1 Answer

Using Camera screen point to ray for look rotation problem... 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