#❗ read me for code sharing guidelines

1 messages · Page 1 of 1 (latest)

cerulean flicker
#

please follow #📖┃code-of-conduct and speak for yourself only

not sure if your discord is not working but by me it posts as a code attachment not showing 300 lines, as directed in that read-me how to post code

nobody needs to hear you clutter chat - if you have something useful to answer to the conversation where people prompted me about seeing my code - it is perfectly acceptable to remain quiet and let others try to help where you dont want to

sullen girder
#

yes, it posts as an attachment because it is too long. See #854851968446365696 for proper code sharing guidelines (which does not include attachements, but rather bin sites) and get off your high horse while you're at it

unborn girder
#

Boxfriend is correct. It's inconvenient to see on the pc and even more so on mobile(where I don't have a choice but to download the file).

#

If you upload it to a paste site, I'll have a look. Unless the issue is solved

cerulean flicker
#

thanks i appreciate the helpfulness

cerulean flicker
unborn girder
#
private void Update()
        {
                if(swimming)
                  ProcessSwimmingMovement();
                else
                {
                  JumpAndGravity();
                  GroundedCheck();
                  Move();
                }

        }
cerulean flicker
#

yes i was testing with a hardcoded condition "if player world position is below <water level Y coordinate>"

unborn girder
#

Then you can implement whatever logic you want

cerulean flicker
#

the question was regarding that particular "logic i want"....

#

i almost got it working... just cant seem to figure out how to take look direction and factor it into the "inputDirection" variable that is used for movement

unborn girder
#

They use a CharacterController. So you just need to apply the desired movement vector to it.

cerulean flicker
#

i basically copied a chunk of code from the Move() method

#

line 181 is where the CharacterController Move command happens

#

using the inputDirection computed just before

#

how to get that inputDirection variable to take into account look direction...

#

there's a variable _cinemachineTargetPitch which has the target pitch rotation

unborn girder
#

By default they use the camera rotation to rotate the character

#

Do you not want that?

cerulean flicker
#

i do want that, i think

#

i think they limit to only move horizontal, and ignore the Y rotation

unborn girder
#

Then it should be working as it is.🤔

#

Does it rotate horizontally with your current code?

cerulean flicker
#

yes, and moves towards the horizontally facing direction just fine

unborn girder
#

Okay. So you want it to rotate vertically as well?

cerulean flicker
#

yes, based on vertical / Y axis look rotation direction

unborn girder
#

That would be rotating on the(or rather around the) X axis

cerulean flicker
#

ah yes... i guess.... i mix them up / am not always precisely sure about which is which

#

on line 177 am i wrong that transform.forward * _input.move.y is not enough to automatically take into account look direction? doesnt it need to take the _cinemachineTargetPitch and do something fancy with quaternion or euler or something to factor it in?..

unborn girder
#

If you look at the camera code, they take the input, multiply it by speed and delta time and use that to rotate the transform.

_cinemachineTargetPitch += _input.look.y * RotationSpeed * deltaTimeMultiplier;
_rotationVelocity = _input.look.x * RotationSpeed * deltaTimeMultiplier;
// clamp our pitch rotation
_cinemachineTargetPitch = ClampAngle(_cinemachineTargetPitch, BottomClamp, TopClamp);
// Update Cinemachine camera target pitch
CinemachineCameraTarget.transform.localRotation = Quaternion.Euler(_cinemachineTargetPitch, 0.0f, 0.0f);
// rotate the player left and right
transform.Rotate(Vector3.up * _rotationVelocity);
cerulean flicker
#

yes exactly, i did see that

unborn girder
#

So all you need to do is do the same for Vextor3.right

#

and y look axis

cerulean flicker
#

i was hoping i can just use that for this move purpose i need, i dont know trig much so im not really sure what i'm doing, it seems those computations help for camera rotation but not for player look direction... or something

cerulean flicker
#

lemme try

unborn girder
#

And then just separate the regular rotation code from swimming one.

cerulean flicker
#

you mean i need to call transform.Rotate() ? i'm not sure that makes sense...

#

i think the output of what i'm trying to do needs to get passed into the call to _controller.Move at the bottom line of that method i cloned

unborn girder
cerulean flicker
#

i think it's a movement operation i'm aiming to achieve, not rotation... i think

#

i do need to use the rotation tho

unborn girder
#

So you don't want to rotate vertically?

cerulean flicker
#

actually i think i left that CameraRotation() in, it is not excluded with my if(swim) condition

#

it will always execute

#

so camera rotation is working as always

unborn girder
#

Then what's the problem?

cerulean flicker
#

i just need to use the rotation look direction and move towards that, including vertically

#

whereas the Move() method for regular FPS movement only moves horizontally along X and Z, when i am in swim/fly mode i also need to move vertically depending on look direction

unborn girder
cerulean flicker
#

i'm not sure i am doing that... can you tell me where do you see that i am doing that?

unborn girder
cerulean flicker
#

it seems by me that rotation works just fine, but moving towards the rotated direction is not working

unborn girder
#

here

inputDirection = transform.right * _input.move.x + transform.forward * _input.move.y;
cerulean flicker
unborn girder
#

You can see that transform.forward is used as the forward direction.

#

It is enough

cerulean flicker
#

yes but i'm afraid that only is effective for X movement and not Y...

#

oh?

unborn girder
#

assuming that the character is rotated

#

Around the x axis

#

which it doesn't by default

cerulean flicker
#

ahhh maybe thats the issue

#

the camera is rotated, but the character remains clamped

unborn girder
#

Yes. The x rotation is not applied to the character.

cerulean flicker
#

i actually want the character to remain clamped, that's a good feature, but i do want it to move in the looked direction.... if possible...

unborn girder
#

Then use the camera forward direction instead of the character one

cerulean flicker
#

ahh

#

is there some way to deduce the correct "forward" based off the _cinemachineTargetPitch variable? or i must rely on the referenced camera object

#

just a minor coding nitpick - to try and implement this independently not relying heavily on other referenced gameobjects... but i guess thats not a big issue worth bothering much...

unborn girder
cerulean flicker
#

ye i guess

#

lemme try

#

aaaand it works 👍