Why can’t I pass “Mouse Y” (from Input.GetAxis(“Mouse Y”) straight into the X axis transform rotation in this situation? (Want to learn more about C#)

Noob/beginner here. I have searched this issue but haven’t found anything on it myself (apologies if this has already been solved/ answered on here). I’m making a super basic FP character controller following this tutorial (https://www.youtube.com/watch?v=PmIPqGqp8UY). It’s great and I’ve got it working, but I ran into some problems along the way and I’m really interested as to why. The final script looks like this (missing some code to lock the mouse to centre of screen):

START OF SCRIPT

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>``
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovementScript_V3 : MonoBehaviour
{
[SerializeField] Transform playerChar_FP_POV = null;
[SerializeField] float mouseSensitivty = 3.5f;
float cameraPitch = 0.0f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
PlayerCameraControl();
}
public void PlayerCameraControl()
{
Vector2 mouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
cameraPitch -= mouseDelta.y;
cameraPitch = Mathf.Clamp(cameraPitch, -90.0f, 90.0f);
playerChar_FP_POV.localEulerAngles = Vector3.right * cameraPitch;
transform.Rotate(Vector3.up * mouseDelta.x * mouseSensitivty);
}
}
``
</code>
<code>`` using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovementScript_V3 : MonoBehaviour { [SerializeField] Transform playerChar_FP_POV = null; [SerializeField] float mouseSensitivty = 3.5f; float cameraPitch = 0.0f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { PlayerCameraControl(); } public void PlayerCameraControl() { Vector2 mouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); cameraPitch -= mouseDelta.y; cameraPitch = Mathf.Clamp(cameraPitch, -90.0f, 90.0f); playerChar_FP_POV.localEulerAngles = Vector3.right * cameraPitch; transform.Rotate(Vector3.up * mouseDelta.x * mouseSensitivty); } } `` </code>
``
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovementScript_V3 : MonoBehaviour
{
    [SerializeField] Transform playerChar_FP_POV = null;
    [SerializeField] float mouseSensitivty = 3.5f;
    float cameraPitch = 0.0f;

    // Start is called before the first frame update
    void Start()
    {
    
    }

    // Update is called once per frame
    void Update()
    {
       PlayerCameraControl(); 
    }

    public void PlayerCameraControl()
    {
        Vector2 mouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

        cameraPitch -= mouseDelta.y;
        cameraPitch = Mathf.Clamp(cameraPitch, -90.0f, 90.0f);

        playerChar_FP_POV.localEulerAngles = Vector3.right * cameraPitch;
        transform.Rotate(Vector3.up * mouseDelta.x * mouseSensitivty);
    }
}
``

END OF SCRIPT

Where the SerializeField Transform “playerChar_FP_POV” is a field which has had a camera (child object of “PlayerChar_Body”) dragged into it so its transform is accessible from the script (see attached image no.1Image showing what Serialize field transform is attached to

While I was experimenting, I found I couldn’t pass “mouseDelta.y” directly into the “PlayerChar_FP_POV” X rotation transform (second last line of script above) the same way I passed mouseDelta.x into the “PlayerChar_Body” Z rotation transform (last line of script above). I first had to create a float “cameraPitch” then assign its value to the inverse of mouseDelta.y (cameraPitch -= mousedelta.y), then clamp the range of “cameraPitch” with Mathf.Clamp (script above- in the last method). Then and only then could I successfully pass the value into “player_FP_Pov” to alter its X rotation transform. If I tried passing mousedelta.y straight into X transform of “playerChar_FP_POV” like so (look in the last method):

START OF SCRIPT

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>```
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovementScript_V3 : MonoBehaviour
{
[SerializeField] Transform playerChar_FP_POV = null;
[SerializeField] float mouseSensitivty = 3.5f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
PlayerCameraControl();
}
public void PlayerCameraControl()
{
Vector2 mouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
playerChar_FP_POV.localEulerAngles = Vector3.right * mouseDelta.y;
transform.Rotate(Vector3.up * mouseDelta.x * mouseSensitivty);
}
}`
```
</code>
<code>``` `using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovementScript_V3 : MonoBehaviour { [SerializeField] Transform playerChar_FP_POV = null; [SerializeField] float mouseSensitivty = 3.5f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { PlayerCameraControl(); } public void PlayerCameraControl() { Vector2 mouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); playerChar_FP_POV.localEulerAngles = Vector3.right * mouseDelta.y; transform.Rotate(Vector3.up * mouseDelta.x * mouseSensitivty); } }` ``` </code>
```
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovementScript_V3 : MonoBehaviour
{
    [SerializeField] Transform playerChar_FP_POV = null;
    [SerializeField] float mouseSensitivty = 3.5f;

    // Start is called before the first frame update
    void Start()
    {
    
    }

    // Update is called once per frame
    void Update()
    {
       PlayerCameraControl(); 
    }

    public void PlayerCameraControl()
    {
        Vector2 mouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

        playerChar_FP_POV.localEulerAngles = Vector3.right * mouseDelta.y;
        transform.Rotate(Vector3.up * mouseDelta.x * mouseSensitivty);
    }
}`
```

END OF SCRIPT

(passing mouseDelta.y straight into “playerChar_FP_POV” X rotation transform; leaving out clamping camera range and inverting input)

The X rotation transform of the “PlayerChar_FP_POV” (the players camera) is locked into place and does not respond to mouse Y axis movement (see picture). Parent object can follow mouse x axis on its Z axis, child object cannot follow mouse Y axis on it’s x axis

Again, I have the controller working fine. But purely from an educational perspective, I’m trying to figure out why this doesn’t work. I feel like understanding that would further my understanding a tad more. I hope this was clear enough, don’t want to waste peoples time!

Unity Version: 2022.3.22f1

Cheers for reading this!!!

Problem explained above, this section is not entirely applicable.

New contributor

HergTheFlerg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật