#Player Y axis rotation with Camera

1 messages · Page 1 of 1 (latest)

round gorge
#

When you rotate the camera the player doesn’t also rotate

#

Is that it?

#

I said that before lol

#

Rotate the player

#

But make the camera a child

#

Or you can use a parental constraint

#

But I don’t reccomend that for this particular issue

#

What’s that video

#

It doesn’t matter

#

You rotate the player

#

Not the camera

#

And the camera will rotate with the luff

#

Same code

#

But for the player instead of camera

#

Don’t rotate the camera rn…

#

Just rotate the player

#

So the player can look right and left

#

Remove everything u have for rotations

#

We’ll start from scratch

#

Now what does input.getsxis(mouse x) do?

#

What does mouse x returns tho

#

What does that int ewusl to

#

Ready for this

#

Make a variable

#

Make it public

#

Set it equal to get axis mouse x

#

Look in the inspector

#

See the number it returns

#

What is that float

#

What is the number that like returns

#

Input.getaxis(mouse x)

#

What float does that return

#

Nice

#

So what that returns is if you are looking right it provided a number

#

A small number

#

Like .4

#

Or 3

#

Whatever

#

Now when you look right that number will always be low

#

But how can you make that a rotations

#

We’ll add it to a variable

#

If you do that

#

Then the variable becomes the x rotations

#

That’s wrong

#

As I am explaining

#

You are setting mouseX to 0.4* sensitivity

#

And you are making that your mouse Rotstion

#

*look

#

No

#

What you have to do is this

#

mouseX += that line

#

Now the longer you are moving your mouse right

#

The more that adds to the variable

#

Which means the higher the Rotstion is

#

If you move it left

#

It’s negative

#

And it will subtract from the Rotstion

#

Do you understand?

#

Be honest if u don’t

#

I can explain it better

#

Birth

#

Both the variable

#

S

#

Make it +=

#

Alright

#

Now

#

Rotate your player’s y Rotstion

#

With mouse x

#

That’s just not how rotations work…

#

Try it…

#

I may be mixed up on the placement

#

But I believe it’s right

#

Yes

#

The player

#

It can be attached to the camera if you have a reference to the player class

#

But it’s smarter to have it on the player

#

Since that is what you are rotating left and right

#

Don’t do this

#

Remove rust

#

*that

#

Because you are making the camera the player’s child

round gorge
#

Did it work?

#

The fix…

#

What I told you.

#

Well with that same quaternion.eular thing

#

Don’t clamp anything

#

Why are you clamping it

#

It’s the x Rotstion

#

Why did you add back that other code

#

I told you to do += remember

#

You just posted a screenshot without it

#

Wel you just create the variables and rotate the player on the y axis with the mouseX

#

Set the players Rotstion with quaternion.eular

#

Player’s Rotstion is equal to quaternion.eular with x as transform.Rotstion.x, y is the x mouse variable, z is transform.Rotstion.z

#

Not too complicated

#

Set the players Rotstion to the player x and z Rotstion and make the y the mosusX variable

#

Alr

round gorge
#

I have to go now but ask in general beginner code. I know it’s frustrating. They can help you understand anything you need to do. When I can get on later I will explain all of this stuff. Watch some unity c# tutorials on rotations

round gorge
#

Did you get it @brisk flare ?

outer fractal
#

Is this the one?

round gorge
#

@brisk flare I helped u so much what r u stuck on

round gorge
#

wdym

#

Did you try what I showed you?

#

show ur code

#

mouse y has an error

#

well u need to do that

#

bro

#

u never set rotations

#

you literally just created variables

#

so it shouldnt work

#

like I said

#

get a reference to the player

#

then do player.transform.rotation = Quaternion.Eular(transform.rotation.x, mouseX, transform.rotation.z)

#

huh?

#

that will make you look left and right

#

did it work?

#

yes

#

thats it

#

no

#

yes

#

did it work

#

yay

#

now do you want to look up and down?

#

mouseY = Mathf.Clamp(mouseY, -90, 90);
camera.transform.localRotation = Quaternion.Eular(mouseY, camera.transform.rotation.y, camera.transform.rotation.z);

#

you can make it more efficient than that

#

but it works

#

yeah thatever

#

not hard at all

#

nice