- Home /
CharacterController and RigidBody
I have some gameobjects which have character controllers, basically I want to explode them, and shoot them up into the air.. typically i'd use rigidbody .AddForce and .AddTorque, these wont work however due to the attached CharacterController, so what i tried to do was detach that then do it, the problem is that when they gameobject is 'dead', it should become a trigger so that I may walk through it, so here is a series of events that must occure in some order to disable character controller, use rigid body for physics, when the enemy hits the ground, make static, turn off gravity(or just disable rigid-body completely) and set collider to trigger;
however its easier said then done, because when I try this, I run into issues such as, removing character controller, then trying to use the rigid body.. just barely has an effect, before ever having a character controller AddForce(0,10,0) worked fine, now after removing the charactercontroller it just barely nudges the object.. then of course there is no good quick way to disable the rigid body after he hits the ground, without some hard-coded script; all in all, the main issue where AddForce now hardly has any effect right after moving the charactercontroller(in the same frame) and im unsure if that has something to do with it.. I did notice that after the first frame, it suddenly works well enough
Check out these scripts on UnifyCommunity :
http://unifycommunity.com/wiki/index.php?title=RigidbodyFPSWalker
http://unifycommunity.com/wiki/index.php?title=PhysicsFPSWalker
Answer by Ingen · Jul 25, 2012 at 03:18 AM
switch your enemy with his fbx with a common rigidbody instead CharacterController, when hitted ,
maybe yield 0.5 second, then do what you need.
Can work?
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddExplosionForce.html
Try this. Attach this script to the object you want to be the collider. Whatever objects you want to be effected, just give them rigidbodies and colliders and watch them fly!
well, i fixed the issue with collision on death, where I create a couple layers and set player and enemies to ignore dead layer, where upon death i set enemy to dead layer; and that works well,
the current problem is that i kill the enemy, which removes the character controller, and adds a rigidbody/collider, I already have been using the addexplosionforce, but the problem at the moment is that for some reason during that swap the enemy fell through the ground so I added a rigidbody.Sleep, and that stopped that issue, but that also effected the addexplosionforce, so i went ahead and added a lil more code to do that on the next frame, and still its not working, so now other then that its fine, but i would like to get that working, i really want them to "fly";
any suggestions? the yield thing wont work because I am not using behaviours to do this, am using the Update
capture the transform.position before the swap, then reset it after :) in other words, just move him back above the floor to his original position
Your answer
Follow this Question
Related Questions
Rigidbody.AddExplosionForce() Not Playing Nice With Trigger Colliders 1 Answer
Making a character controller work with physics 1 Answer
Parenting the Character Controller to rigidbody: won't stick 1 Answer
Touch input to move rigidbody using explosion force in C# 0 Answers
Earth quake with physics? 1 Answer