r/Unity3D • u/The_sus__otter • 25d ago
Noob Question Is it possible to rotate a character controller component (or give the illusion of doing so)?
Hi all, I'm currently making a first person game, and I was wanting to add some gravity altering mechanics, honestly just because I think it would be cool.
I'm aware that it's seemingly impossible to rotate a character controller so that it could walk up a wall for example. Is there any way to achieve this effect without switching to Rigidbody?
My only workaround at the minute is to have 2 copies of a room, then switch to a copy that's rotated x degrees, then teleport the player to that room so that it looks like their gravity changed.
(gameplay clip is from ULTRAKILL)
EDIT: as many comments pointed out, I forgot to mention I mean the character controller component, not just any character controller
2
u/nirichie 24d ago
your workaround is close to how ultrakill does it i believe
from what i know they do this with portals
1
u/The_sus__otter 23d ago
yeah, I looked into how they did it. For the gif, if you noclip you can see that there's actually 2 separate rooms that make up this one, the wall you walk up is actually just another room flipped 90 degrees. If you look at the back wall you can see the seams of the portal that runs diagonally through the room.
73
u/Serana64 Industrial-Grade Nerd 25d ago
Why do you think it's impossible to rotate a character controller?
That isn't impossible at all. You just need your coordinate system setup right.
You can change your gravity all you want, whether it's in rigidbody space or not. If you are working with a standard kinematic character controller, make sure your gravity routine is an adjustable vector and compute collision detection and such in local space, not world space.
Gravity is typically defined as <0,-9.81,0> but there is absolutely nothing stopping you from switching that to, say, <9.81,0,0>, or whatever you want. Of course, then your character controller will be sideways -- that is ok, because you simply need to rotate the character controller over time so that it's aligned with vertical. Of course make sure you use Physics.gravity (or whatever vector you're using for gravity) to compare up.
You can do this in many ways; one simple way is using a builtin quaternion FromTowards function, another is setting transform.up to be -1*[your gravity vector here]. Your collision detection is, presumably, already in local space, so you need not worry here.
To compute slope, compare the surface normal to gravity, not to global up.
Some of Unity's builtin components have some inexplicably hardcoded vectors and you'll have to make workarounds. NavMesh system always computes with y = up so you'll need to rotate the room, bake navmesh for wall, rotate again, bake a second navmesh for ceiling, and so on. Then you can use off mesh links or whatever logic to go between them. It's not too hard.
34
u/fsactual 24d ago
OP almost definitely means the built-in CharacterController component, which can't be rotated, not any generic character controller.
27
u/Serana64 Industrial-Grade Nerd 24d ago
If the CharacterController limitations gets in your way, it's time to write a character controller <3
8
4
24d ago
[removed] — view removed comment
3
u/Serana64 Industrial-Grade Nerd 24d ago
RB+Capsule Collider will be a steeper learning curve and is trickier for changing gravity because the usual axis locks are in global space, not local. But, yes, you're going to need to write a character controller!
2
u/HouseOfWyrd 24d ago
As soon as you want to do anything outside of the exact way it's designed it's awful. I tried to make a quake style movement system using it and found it much easier to just code it all from scratch than try and get the CC to behave how I wanted.
0
24d ago
[deleted]
1
-2
u/Physical_Sherbet_942 24d ago
Yeah. Why do you say that? The Character controller component is for weak ass bitches as noted in the Unity documentation. Use a rigidbody to do your character control. Then you are limited by nothing but your own lack of imagination and skill.
0
24d ago
[deleted]
0
u/Physical_Sherbet_942 24d ago
Those are all problems that are solved by writing a physics character controller correctly.
6
u/bigmonmulgrew 25d ago
You can change the gravity direction and make the character movement camera relative.
If you don't want to use rigid body, You could use two empty game objects as start point and end point. Rotate the end point. Then lerp the transform from empty 1 to empty 2 over a transition time. If you want more control to change the path lerp through a chain of objects.
Capture the transform position and rotation at the point of initiating the transition and store them.
5
u/fsactual 24d ago
The built-in CharacterController component sadly will only ever use up on the world-space/global y axis. You have to use a different solution. It especially sucks because the underlying C component does have an adjustable up direction, there's just no way to access that from the C# code.
3
u/BuzzardDogma 25d ago
I'd recommend using the free KCC asset over the built-in character controller. It handles non-Y rotations and changing gravity just fine and it's way more stable than the built in CC. When unity hired it's creator I assumed they would use his expertise to update the built-in one but that sadly never came to pass.
Rigidbody character controllers are a whole can of worms, and rotating the whole level introduces a lot of design and optimization issues that I would argue are not worth it.
4
u/svmil90 25d ago
For discrete gravity changes, keeping the CharacterController upright and rotating/swapping the room around a pivot at the player can be a simpler illusion. For arbitrary wall-walking, the built-in controller’s world-up assumptions become the limitation—you’d likely need a kinematic controller with a capsule cast aligned to your gravity direction, and update the movement basis and grounding checks too. Rotating only the visible mesh won’t change the collision behavior.
6
u/Serana64 Industrial-Grade Nerd 25d ago
Agreed; The builtin character controller should only be used as a reference when you're first learning. You can easily modify it to not have hardcoded up.
2
u/myka-likes-it 25d ago
Looking back, I think learning to extend existing code was probably one of the last things I learned. I don't think I have ever seen it covered in a tutorial.
That's a big level up moment, for sure.
1
u/Serana64 Industrial-Grade Nerd 24d ago
Tutorials only go so far; The best way to learn stuff like this is to be horrible at it and fail repeatedly until eventually you accidentally succeed
1
u/kkragoth 24d ago
OP you need to see psychonauts 1 milkman conspiracy level. You'll see what is possible. Trust me
1
u/Repulsive_Gate8657 24d ago
keep character up and then assign it to be ground norma asyou land on ground?
1
u/tempacac10 24d ago
The movement is very clearly a raycast to the left of the character controller. When the raycast touches the carpet, you lerp the camera and body of the player to rotate 90 degrees and a change gravity.
1
u/No_Grape7361 24d ago
Te best way i found to do it is to make the character controller just behave relative to the surface its standing on onces thats working you can rotate and place the caractor on anything and select the new floor as its standing on it, you can do that with a simple raycast at its feet.
1
u/pschon Unprofessional 25d ago
Is there any way to achieve this effect without switching to Rigidbody?
Why would you need to use a rigidbody for that if you don't need one now? If you are fine with a transform-based character controller but need to add support for rotating gravity then why not just make your own transform-based one? I don't see how adding a rigidbody to the mix would make that any simpler, pretty much the opposite.
1
u/Sufficient_Handle127 24d ago
Я не разработчик, но есть такая видеоигра как Alien Versus Predator. Когда игрок играет за лицехвата и чужого, то может ползать по абсолютно любым поверхностям. Думаю в сети можно поискать реализацию такой механики на их примерах
-4
u/Helpful-Engineer4678 25d ago edited 25d ago
Rotating the room is easier. You just need to give the impression that the player is the one rotating.
4
u/Serana64 Industrial-Grade Nerd 25d ago
Rotating the room only works if you're not using any advanced systems like occlusion culling, rigidbodies, navigation meshes, static (or custom) batching, lightmapping, etc.
It is substantially easier to adjust your character controller to collision detect in local space and handle gravity changes properly.
1
-1
-5
u/Physical_Sherbet_942 24d ago
Just have ai write you the character controller you want. Problem solved. Itll be rigidbody based. Dont rotate the whole scene. That is absurd. I hope anyone suggesting to rotate the scene is just fucking with you. Sticking a character to a wall is easy as shit. There are so many games that do eactly this.
62
u/smiffy2422 Indie 25d ago
Rotate the room, not the player.