#camera rotation

1 messages · Page 1 of 1 (latest)

devout trench
#

.

steep geyser
#

alright

#

so

devout trench
#

if you want to makae your movement depend on the camera's orientation, you'll need to use the camera's orientation

#

you can get the camera's forward and right vectors, and compute your movement vector based on those

#

with the caveat that you should then get rid of the Y component (so that you don't walk into the sky)

steep geyser
#

got it

#

funny thing, though?

devout trench
#

and then fix the length of the vector, so that looking down doesn't make you slower

steep geyser
#

the project that this is based on, which I got in my own folders to test, has the issue resolved

#

and I am sitting on my ass going wtf

#

also, orientation is the orientation of the camera

#

but no matter where I'm looking, it's still workingoff world axis

devout trench
#

so if you click on the orientation field in the inspector, it takes you to the main camera?

steep geyser
#

... no

#

just the center of the player model

#

which is bound to a capsule collider

devout trench
#

assumptions cause grief!

#

if orientation is used elsewhere, then don't mess with it

#

just use Camera.main.transform instead

steep geyser
#

and replace ahat lines with that?

#

just orientation?

devout trench
#

yes, since orientation is a transform

#

Camera.main.transform is a reasonable replacement

steep geyser
#

well...

#

i tried that

#

and started to arise to the heavens at a certain point

#

plus I lost my ability to jump, and still stuck on world axis

devout trench
#

show your new code (you can just copy the part that computes the movement vector)

steep geyser
#
private void MovePlayer()
    {
        // calculate movement direction
        moveDirection = Camera.main.transform.forward * verticalInput + Camera.main.transform.right * horizontalInput;

        // on slope
        if (OnSlope() && !exitingSlope)
        {
            rb.AddForce(GetSlopeMoveDirection(moveDirection) * moveSpeed * 20f, ForceMode.Force);

            if (rb.velocity.y > 0)
                rb.AddForce(Vector3.down * 80f, ForceMode.Force);
        }

        // on ground
        else if (grounded)
            rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);

        // in air
        else if (!grounded)
            rb.AddForce(moveDirection.normalized * moveSpeed * 10f * airMultiplier, ForceMode.Force);

        // turn gravity off while on slope
        rb.useGravity = !OnSlope();
    }```
#

thats all i did

#

and it did that

devout trench
#

currently, looking up will let you walk up

#
moveDir = /* existing code */
Vector3 original = moveDir;
moveDir.y = 0;
moveDir = moveDir.normalized * original.magnitude;
#

this will get rid of the vertical component, then restore the original length

steep geyser
#

well... no

#

walking back makes me walk up

#

looking direction has nothing to do with that

devout trench
#

are you sure it has nothing to do with that

steep geyser
#

positive

#

looked up my ass and down at the fround

#

its the s key that does the flying thing

#

left right and front aren't affected

devout trench
#

so if you look almost straight up and hold W, you walk forwards correctly?

steep geyser
#

yep

#

though the script affecting the drag, and script to jump, aren't usable for the time being

devout trench
#

do you walk forwards at the same speed as if you were looking straight ahead, though?

steep geyser
#

yes

#

also

#

in good news

#

the character is now moving relative to the camera

steep geyser
#

whereever its facing, the camera moves

#

one sec

#

one second

devout trench
#

oh, you normalize moveDirection

#

that explains why it's working

steep geyser
#

except its not

devout trench
#

note that this will make your game feel very weird if you use a controller, since it'll mean that even a tiny movement input turns into 100% movement speed

steep geyser
#

ffs... alright. alright

#

not blaming you

devout trench
#

I see no reason for moving backwards to behave differently from moving forwards

#

maybe if your collider isn't symmetrical, it could be digging into the ground when going backwards, or something like that

steep geyser
#

symmetrical collider?

#

also, something about

UnityEngine.Transform:set_forward (UnityEngine.Vector3)
ThirdPersonCam:Update ()```
devout trench
#

what line number?

steep geyser
#

it does not say

devout trench
#

oh right, it doesn't show up

steep geyser
devout trench
#

well, it's one of those four .forward = lines

#

one of them has a zero vector

steep geyser
#
        Vector3 viewDir = player.position - new Vector3(transform.position.x, player.position.y, transform.position.z);
        orientation.forward = viewDir.normalized;

        // rotate player obj
        if (currentStyle == CameraStyle.Basic || currentStyle == CameraStyle.Topdown)
        {
            float horizontalInput = Input.GetAxis("Horizontal");
            float verticalInput = Input.GetAxis("Vertical");
            Vector3 inputDir = orientation.forward * verticalInput + orientation.right * horizontalInput;

            if (inputDir != Vector3.zero)
                playerObj.forward = Vector3.Slerp(playerObj.forward, inputDir.normalized, Time.deltaTime * rotationSpeed);
        }```
#

this is the only chunk that can be containing it

#
        {
            Vector3 dirToCombatLookAt = combatLookAt.position - new Vector3(transform.position.x, combatLookAt.position.y, transform.position.z);
            orientation.forward = dirToCombatLookAt.normalized;

            playerObj.forward = dirToCombatLookAt.normalized;
        }```
#

unless it's bitching about this

devout trench
#

perhaps you should diagnose it

#

log the values you're using

#

that's how i track down such things

steep geyser
#

well shit

#

i'll solve that later

#

now i gotta figure out how to get the character to orientate themselves to have their backs face the camera whenever w is hit

#

thanks

steep geyser
#

oh my fucking god

#

holy fuck I am a dumbass