#Mouse movement

1 messages · Page 1 of 1 (latest)

trail violet
#
    void Update()
    {
        float mousex = Input.GetAxis("Mouse X") * MouseSens;
        float mousey = Input.GetAxis("Mouse Y") * MouseSens;

        playerBody.Rotate(Vector3.up * mousex);
    }

This is what the code looks like now

supple tiger
#

Did you set mouseSens to something ?

trail violet
#

it has been set to 100f

supple tiger
#

Where ? Because the inspector will overwrite values from the code

trail violet
#
public class MouseLook : MonoBehaviour
{
    public float MouseSens = 100f;

    public Transform playerBody;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float mousex = Input.GetAxis("Mouse X") * MouseSens;
        float mousey = Input.GetAxis("Mouse Y") * MouseSens;

        playerBody.Rotate(Vector3.up * mousex);
    }
}
```This is the whole class
supple tiger
#

What is the value for mouse sense in the inspector ?

trail violet
#

you mean this?

supple tiger
#

Ok do you get any errors in the console ?

trail violet
#

nopr

mental bough
#

Make sure to save your script or make sure the script is applied or restart unity

trail violet
#

i will try restarting unity

#

didnt work

#

the script should be on the Main Camera right?

supple tiger
#

The script can be anywhere

trail violet
#

ok

#

will it still run?

supple tiger
#

As long as you dragged the correct transform into the playerbody

supple tiger
trail violet
#

Do i need to do anything with this?

mental bough
supple tiger
#

Yes you need to attach the script to a gameObject in the scene

trail violet
#

because thats what brackeys told me to do

mental bough
#

Do you have the script attached to the camera

trail violet
#

yes

mental bough
#

And you have the player transform?

#

Reference

trail violet
#

This is the script in the camera

#

cylinder is the player

supple tiger
#

Do a Debug.Log(mousex); right before the rotate calk and see what pops in the console

trail violet
#

it goes negative when I move the mouse left, and goes positive when I move the mouse right

analog bluff
#

Can you show a screenshot of the player object, the cylinder

trail violet
analog bluff
#

the scene

trail violet
analog bluff
#

Ok so that's completely symmetrical. How do you know it's not rotating?

supple tiger
#

Look at its transform. Does the rotation value change ?

supple tiger
#

What was the problem

trail violet
#

wait nvm

#

not quite fixed

#

because the main camera is a child of the player

#

so it is locked to the player

#

so if the player rotates, the main camera should rotate too

supple tiger
#

Welk yes

trail violet
#

I think I solved it

#

let me do some more testing

#

I have not

#

The camera rotates with the mouse

#

but

#

when i try moving the player around, it doesnt work

#

the player still faces the same direction

#

i think i see

#

I fixed that but now I have another problem

#

whenever I start my player is always flung off the plane

#

@supple tiger

supple tiger
#

Well that sounds like a completly different problem

#

I gtg now sorry

trail violet
#

:(

#

can you find someone else to help me?

supple tiger
#

Im not a teacher at your school. Ask in the channels and find someone yourslef UnityChanThumbsUp