#camera rotation
1 messages · Page 1 of 1 (latest)
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)
and then fix the length of the vector, so that looking down doesn't make you slower
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
so if you click on the orientation field in the inspector, it takes you to the main camera?
assumptions cause grief!
if orientation is used elsewhere, then don't mess with it
just use Camera.main.transform instead
yes, since orientation is a transform
Camera.main.transform is a reasonable replacement
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
show your new code (you can just copy the part that computes the movement vector)
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
ah, you still need to do this.
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
well... no
walking back makes me walk up
looking direction has nothing to do with that
are you sure it has nothing to do with that
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
so if you look almost straight up and hold W, you walk forwards correctly?
yep
though the script affecting the drag, and script to jump, aren't usable for the time being
do you walk forwards at the same speed as if you were looking straight ahead, though?
did you make this change?
whereever its facing, the camera moves
one sec
one second
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
except its not
this part, I mean.
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
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
symmetrical collider?
also, something about
UnityEngine.Transform:set_forward (UnityEngine.Vector3)
ThirdPersonCam:Update ()```
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
what line number?
it does not say
oh right, it doesn't show up
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
perhaps you should diagnose it
log the values you're using
that's how i track down such things