- Home /
Multiple controllers on same Player object...
This is not quite a code question, but more of a capabilities/procedures question. My player object will have several different modes corresponding to land-based or air-based travel. These modes will be selectable by the player (and will change the mesh). I would like to use the character controller for the land-based movement (primarily because I am not secure enough in my coding skills to think I can handle all of the collisions as well as the standard controller can). However, I need the ability to change collider shapes (not possible with the character controller... it's always a capsule) as well as the controller to one more suited to airplane-style movement.
I've tried creating a player parent gameobject, parenting different meshes with their own controllers to it, and activating and deactivating them as needed. Because the controllers are on the meshes, only the mesh (and not the player object) moves. I can re-parent all of the other meshes (as well as the player object) to the "selected" mesh, but that is asking for code/controller issues.
There has got to be a more "elegant" solution. Any ideas on how I could swap between controllers, colliders, and meshes without having to destroy and instantiate them or swapping out tons of parent objects?
Any insights would be greatly appreciated. I'm at the point where I'm afraid I will have to jettison the character controller and just code the whole different sets of controllers together (in which case I'll probably be posting a ton of collision questions... hehehe)...
Answer by The_r0nin · Nov 26, 2010 at 03:13 AM
OK, I figured out an inelegant but workable solution. I created a player object with a script that selects between the various modes. I created three different objects that contain the meshes, colliders, and controllers for each of the three modes. I then cached (in the player script) the objects and renderers of each object.
When I want to change modes, I disable all of the mode objects and their renderers (using the cached variables), then enable (or set active) the mode object and renderer I want. I then move it to the player object position and parent the player object and camera to it.
Anytime I need to transmit info to the player (say reduce hitpoints due to damage), I Broadcast a message (still looking for a better method... I might cache the player object in each mode object) so that the damage script on the player object will be run.
Not the best solution, I'm sure... but the best I can come up with. Hopefully it will help someone else in my position.
Your answer
![](https://koobas.hobune.stream/wayback/20220613084304im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Piling up objects and transporting them 1 Answer
Pulling boxes 0 Answers
physics.OverlapSphere colliders 1 Answer
Help with Colliders? 0 Answers