Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System;
using UnityEngine;


public class CameraLook : MonoBehaviour
{
    public float mouseSpeed = 100f;
    public Transform playerBody;
    float xRotation = 0f;

    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }
    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * mouseSpeed * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSpeed * Time.deltaTime;


        xRotation -= mouseY;

        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);

        playerBody.Rotate(Vector3.up * mouseX);


What I have tried:

I tried using this line
playerBody.Rotate(Vector3.up * mouseY); but it didn't work.
Posted
Updated 22-Jan-21 19:50pm

1 solution

Clearly the rotate method doesn't know what your variables are called. I think you need to make this your second parameter

Unity - Scripting API: Transform.Rotate[^]
 
Share this answer
 
Comments
Mackenzee Ferren 23-Jan-21 13:08pm    
I'm kinda new to scripting so what would be the second parameter?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900