#looking around system

1 messages · Page 1 of 1 (latest)

civic cloak
#

hello

boreal ginkgo
#

hi

civic cloak
#

ok so

boreal ginkgo
#

so uh this is the code:
public void playerMouse()
{
float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;

    xrot -= mouseY;

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

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

    transform.Rotate(Vector3.up * mouseX);

}
civic cloak
#

alright

#

explain how it works please

boreal ginkgo
#

uh

#

so float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;

#

gets the input

civic cloak
#

alright

boreal ginkgo
#

oh

civic cloak
#

ah

#

so

#
    public void playerMouse()
    {
        float mouseX = Input.GetAxis("Mouse X") * sensitivity;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity

        xrot -= mouseY;

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

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

        transform.Rotate(Vector3.up * mouseX);

    }```
boreal ginkgo
#

and this xrot -= mouseY;

civic cloak
#

mhm

civic cloak
#

alright

boreal ginkgo
#

if its +, it would be flipped

civic cloak
#

ah

boreal ginkgo
#

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

#

this clamps the xrot

#

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

    transform.Rotate(Vector3.up * mouseX);
civic cloak
#

mhm

boreal ginkgo
#

these just rotates the player and cam

civic cloak
#

alright

#

may I ask a few more questions ?

boreal ginkgo
#

yeah

civic cloak
#

ok

#

so

#

when i copied the code into my script a few errors popped up

boreal ginkgo
#

yup

civic cloak
#

how would i fix these

boreal ginkgo
#

declare the variables, put a semicolon in float mouseY = Input.GetAxis("Mouse Y") * sensitivity

boreal ginkgo
# civic cloak how would i fix these

declare variables declare variables declare variables declare variables declare variables declare variables declare variables declare variables

civic cloak
#

so like

#
public float xrot = 1f;
boreal ginkgo
#

nonono

civic cloak
#

hm

boreal ginkgo
#

just do public float xrot;

civic cloak
#

ah

#

ok

#

there is 1 last error

boreal ginkgo
#

whaaa

civic cloak
#
cam.transform.localRotation = Quaternion.Euler(xrot, 0f, 0f);```
boreal ginkgo
#

hm

civic cloak
#

yes

boreal ginkgo
#

did you make the cam a gameobject

civic cloak
#

what

#

this is all i have

boreal ginkgo
#

the cam variable

civic cloak
#

?

boreal ginkgo
#

show ur full code

civic cloak
#

ok

#
using UnityEngine;
using System.Collections;
 
public class PlayerController : MonoBehaviour {
 
//public
public CharacterController controller;
public float sensitivity = 3f;
public float xrot;
public float cam;
public float speed = 3f;
public float gravity = -23f;
public float jumpHeight = 3f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;

//bool
bool running;
bool isGrounded;

//vector3
Vector3 velocity;

void Update()
{
    if (Input.GetKey(KeyCode.LeftShift))
            {
                    running = true;
            }

            isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
    if (isGrounded && velocity.y < 0)
    {
        velocity.y = -7.3f;
    }
    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");
    Vector3 move = transform.right * x + transform.forward * z;
    if (running == true && isGrounded)
            { 
                speed = 6f;
                running = false;
            }
    else 
    {
    speed = 3f;
    }
    Vector3 run = move * speed * Time.deltaTime;
    controller.Move(run);
    if (Input.GetButtonDown("Jump") && isGrounded)
    {
        velocity.y = Mathf.Sqrt(jumpHeight * gravity * -2f);
    }
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
}
    public void playerMouse()
    {
        float mouseX = Input.GetAxis("Mouse X") * sensitivity;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity;

        xrot -= mouseY;

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

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

        transform.Rotate(Vector3.up * mouseX);

    }
}
boreal ginkgo
#

why the frick is the camera a float lmao

civic cloak
#

idk lmfao

#

is it suppose to a transform

boreal ginkgo
#

yes lol

civic cloak
#

oh lol

#

1sec

#

ok

#

so

#
public transform cam;```
#

line 10

boreal ginkgo
#

please use a proper ide

civic cloak
#

ide?

boreal ginkgo
#

what tool do you use

#

visual stuido?

civic cloak
#

mhm

#

yes i use vsc

boreal ginkgo
#

configure vsc

civic cloak
#

alr 1sec

boreal ginkgo
#

you will get autocorrect

civic cloak
#

ah

boreal ginkgo
#

if you get autocorrect, you will get the reccomendation Transform

civic cloak
#

alrigtht

boreal ginkgo
#

what

#

can you screenshare

civic cloak
#

yes