Search Results
7/13/2025, 9:28:13 AM
>>531038192
It's a bit jank but it wasn't that hard to figure out. I can walk on any surface and the rigidbody auto-aligns itself.
Basically I spherecast down to get the normal of the surface and use that for gravityDirection. gravityMagnitude is the 9.81f magic number that Unity has but you could adjust it if you want. All this in FixedUpdate.
>Vector3 gravity = gravityDirection.normalized * gravityMagnitude;
>rb.AddForce(gravity, ForceMode.Acceleration);
>Vector3 desiredUp = -gravityDirection.normalized;
>Quaternion currentRotation = transform.rotation;
>Quaternion targetRotation = Quaternion.FromToRotation(transform.up, desiredUp) * currentRotation;
>rb.MoveRotation(Quaternion.Slerp(currentRotation, targetRotation, alignRotationSpeed * Time.fixedDeltaTime));
Rotation is
>playerTransform.Rotate(Vector3.up, mouseX, Space.Self);
>cameraPitchTransform.Rotate(Vector3.right, -mouseY, Space.Self);
With sort of this >>531035353 structure but I'm using Cinemachine so the Virtual camera is not a child object but uses the Pitch as it's follow target. Cinemachine doesn't really bring anything to this if it's in first person so you could do without and put the camera as child or have a script on camera that updates its pos and rot in lateUpdate.
You'd really wanna improve upon the raycasting and probably get some average to make moving on uneven surfaces feel better.
t. >>531032141
It's a bit jank but it wasn't that hard to figure out. I can walk on any surface and the rigidbody auto-aligns itself.
Basically I spherecast down to get the normal of the surface and use that for gravityDirection. gravityMagnitude is the 9.81f magic number that Unity has but you could adjust it if you want. All this in FixedUpdate.
>Vector3 gravity = gravityDirection.normalized * gravityMagnitude;
>rb.AddForce(gravity, ForceMode.Acceleration);
>Vector3 desiredUp = -gravityDirection.normalized;
>Quaternion currentRotation = transform.rotation;
>Quaternion targetRotation = Quaternion.FromToRotation(transform.up, desiredUp) * currentRotation;
>rb.MoveRotation(Quaternion.Slerp(currentRotation, targetRotation, alignRotationSpeed * Time.fixedDeltaTime));
Rotation is
>playerTransform.Rotate(Vector3.up, mouseX, Space.Self);
>cameraPitchTransform.Rotate(Vector3.right, -mouseY, Space.Self);
With sort of this >>531035353 structure but I'm using Cinemachine so the Virtual camera is not a child object but uses the Pitch as it's follow target. Cinemachine doesn't really bring anything to this if it's in first person so you could do without and put the camera as child or have a script on camera that updates its pos and rot in lateUpdate.
You'd really wanna improve upon the raycasting and probably get some average to make moving on uneven surfaces feel better.
t. >>531032141
Page 1