- Home /
Using rigidbody for collisions only, not movements?
Hi, i have read that we can use a characterController and a rigidbody set to "kinematic", and then turn off the kinematic when there is a collision. How could we do this? I have this kind of code :
function seekPlayer(){
var moveDirection=Vector3.zero;
directionToPlayer=player.transform.position-transform.position;
distanceToPlayer=Vector3.Distance(transform.position,player.transform.position);
var playerAngle=Vector3.Angle(directionToPlayer,transform.forward);
if((Mathf.Abs(playerAngle)<visionAngle && distanceToPlayer<visionRange) || canSeePlayer==true){
Physics.Linecast(transform.position,player.transform.position,hit,~sameLayer.value);
moveDirection=transform.forward;
if (hit.collider.name==player.collider.name){
and when i add a rigidbody to my characters, i get a reference null at :
if (hit.collider.name==player.collider.name){
Is it possible to still use the characterController to move the character, and the rigidbody to simulate the collision only?
Thanks
@Fattie : thanks Fattie, it is more clear now, is it possible to use the three of them : a characterController with a rigidbody and a capsule collider for example? I have a human character to move... (and i will maybe add more "colliders" if i can, for the arm, legs, body etc.) Thanks again
@Fattie, thanks, alright, i have read that to move a character, we should use a characterController (http://answers.unity3d.com/questions/34977/Stairs-and-Step-Offset-Character-Controller-X-rigidbody-best-solution-for-character.html), what kind of game did you make without the characteController? Do you make your characters move with rigidbodies only?
@Fattie, okay, thanks for the answer, i don't really want to use a charactercontroller over a rigidbody, because i did not know the details behind all of that. but thanks it's interesting, i am using a rigidbody ins$$anonymous$$d now with the code from the wiki FPSWalker, and trying to figure out how angrybots works, but it's not really easy for the moment... ;) Okay, thanks anyway, problem solved!
I zooped my first comment, just to keep the board tidy since there is no answer here
BTW zoop is the cool new verb meaning to change the nature of something, changing it's taxonomy, changing it from one category to another ! :)
Answer by Fattie · Aug 31, 2012 at 10:57 AM
You're mixing-up rigidbody and collider. Collisions entirely relate to colliders. Rigidbody is not involved in collisions or raycasting. Hopefully that helps in some way, cheers