- Home /
Character Controller and Camera for Faux gravity..(Mario Galaxy)
So many people ask the question about Mario Galaxy, and I spend my spare time to create the same effects.I read their request and question, and I decide to use
transform.rotation = Quaternion.FromToRotation (Vector3.up, (transform.position - Vector3.zero).normalized);
to rotate my character, and it works. But there is a problem, the collision capsule of Character Controller do not rotate, it makes a lot of trouble about collision, such as hit the barricade.
looks like this:
Secondly, about the camera, I want to put my camera in front of the character, even though the character have rotated. Does it have any function I can use??
Thanks for your help!!
Answer by runevision · Jan 26, 2011 at 10:04 AM
If you need a variable gravity / up direction for your character, you need to use a Rigidbody with a Capsule Collider and not a CharacterController. Rotating CharacterControllers around anything other the Y axis just doesn't work, and rotating the entire world is very sub-optimal and error prone physics-wise.
The Locomotion System project has a demo scene with a character with variable up direction, so that's one example of how to do it.
Thanks Rune Skovbo Johansen, I will download that project to figure out how to make it.. I am very appreciated..
I was trying the same thing, and rigidbody doesn't work well because of velocity e.g. when I fall down a slope, my character keeps moving.
Answer by Jesse Anders · Jan 26, 2011 at 06:33 AM
Yes, the collider for the character controller does not rotate, which makes the character controller component less than suitable for this particular application.
If everything else is working more or less the way you want, the easiest solution (although not an ideal one) would probably be to adjust the capsule parameters to make it a sphere. Obviously a sphere is a poorer approximation of a typical humanoid shape than a capsule, but I imagine it could work, depending on the circumstances.
Ha, my friend tell that few days ago, but I hope I can find "precisely" solution for it. and I believe the collide would more accurate. How about the camera one? can you give me some advices?
Adjusting the CharacterController height to be a sphere won't work correctly. The CharacterController handles ground and walls differently. No matter if the shape is a sphere, settings like Slope Limit and Step Offset still assumes that Y is up.
Answer by rob49152 · Jan 26, 2011 at 07:49 AM
Instead or rotating the character which will cause the problems you describe. I'd rotate the universe around the character and then rotate the camera back the opposite way. This should have the same effect that you want but the characters feet will remain the bottom of the character controller.
If you parent everything in the 'universe' to an emtpy game object, then reverse what you want the characters angle to be, then reverse the cameras z rotation it should work... in theory... in my brain it does.
Not sure about that; transfor$$anonymous$$g the world to give the effect of a camera transformation is rarely the optimal solution. Also, although it might work, I imagine constantly rotating/moving every collider in the simulation other than the character controller would be a bit of a stress test for the physics engine. (Rotations are typically more difficult to handle as far as collision detection goes than linear motion against static objects.)
Jesse's right; and especially moving static colliders is rather a no-no if you want performance.
So, do you have any good solution have good performance and same effect? I try it if I fix the character's position, there are no collision happened(the barricade is trigger), that's why I make the surface ball fixed, and character walk on the ball surface. $$anonymous$$aybe I should try to fix the character and camera, when I press forward, just set surface ball rotate faster... does it works?
Your answer
Follow this Question
Related Questions
Mario Galaxy -ish controls problem 1 Answer
Faux Gravity, spinning at bottom of sphere 0 Answers
Trying to figure out how to translate these gravity script to Javascript 2 Answers
Multiple Planets with their own gravitational pull 1 Answer
Click to move player while avoiding jitter at edges 0 Answers