#❗ read me for code sharing guidelines
1 messages · Page 1 of 1 (latest)
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
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
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
lemme know if you had a chance to have a look there (for convenience: https://kopy.io/x1szV )
There are several options, but I'd just add a new "movement state" in update.
private void Update()
{
if(swimming)
ProcessSwimmingMovement();
else
{
JumpAndGravity();
GroundedCheck();
Move();
}
}
yes i was testing with a hardcoded condition "if player world position is below <water level Y coordinate>"
Then you can implement whatever logic you want
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
They use a CharacterController. So you just need to apply the desired movement vector to it.
Share what you have so far.
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
By default they use the camera rotation to rotate the character
Do you not want that?
i do want that, i think
i think they limit to only move horizontal, and ignore the Y rotation
Then it should be working as it is.🤔
Does it rotate horizontally with your current code?
yes, and moves towards the horizontally facing direction just fine
Okay. So you want it to rotate vertically as well?
yes, based on vertical / Y axis look rotation direction
That would be rotating on the(or rather around the) X axis
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?..
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);
yes exactly, i did see that
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
oh?
lemme try
And then just separate the regular rotation code from swimming one.
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
That or add up both rotation before calling it once.
i think it's a movement operation i'm aiming to achieve, not rotation... i think
i do need to use the rotation tho
So you don't want to rotate vertically?
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
Then what's the problem?
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
You're already doing that. You just don't rotate your character around the X axis.
i'm not sure i am doing that... can you tell me where do you see that i am doing that?
Yeah, that's what we were doing
it seems by me that rotation works just fine, but moving towards the rotated direction is not working
here
inputDirection = transform.right * _input.move.x + transform.forward * _input.move.y;
right but i thought ☝️ ?
assuming that the character is rotated
Around the x axis
which it doesn't by default
ahhh maybe thats the issue
the camera is rotated, but the character remains clamped
Yes. The x rotation is not applied to the character.
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...
Then use the camera forward direction instead of the character one
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...
There is. But I think it would be simpler just to use camera forward