x


Having a character Controller have physics..

I have a player made from the standard character controller, all I want is for him to be able to bump into stuff, and knock it about... If I add a cube and give it a rigid body... I would expect that to work.. but no.

As the character controller is the built in Unity controller i would expect it to work with physics. Obviously not, any clues as to what I might try?

Please dont say, "write your own" because if I could I would... just explain me the concept, Ill figure it out!

:)

Mark

more ▼

asked Feb 02, 2013 at 09:10 PM

markfrancombe gravatar image

markfrancombe
150 49 62 66

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

character controller isn't affected by physics because it's not desired. We don't want the player to bounce and then fall over when he runs into a wall. Instead we want it's behaviour to be completely programmed.

A character controller is basically a kinematic rigid body that comes with some nice features like stepping stairs. It's been made as a solution for characters because a)gamephysics are not real physics, we just do some limited simulation for a few fancy tricks b)people are not rigidbodys, so we can't really emulate their behaviour with a rigid body simulation (for example we don't accelerate or deaccelarte like a rigid body sphere does)

When doing a character you can either: 1.Make a character controller and code all the physics-like behaviour you want (like getting pushed around by an exploding mine, falling down etc.) 2.Make a rigidbody and try to filter out all the behaviour you don't want

I def prefer controller over rigidbody for player characters, to make sure we've got complete control, so that we never get stuck in walls and controls never react awkwardly. People argue over what to choose, you can def go both ways but I found the arguments for controllers convincing. For NPCs there's more liberty, you can do some funky stuff with rigid bodys, especially with joints, like them wildly flying around when they get shot etc.

There are probably tons of controllerscripts in the unify-wiki.

+Check out the Physics part in the manual.

more ▼

answered Feb 02, 2013 at 10:10 PM

schaddemm gravatar image

schaddemm
195 11 13 15

Thanks for the reply, I dont need flying bodies after explosions,(but got me thinking... maybe I do??) Just would like to be able to bump into chairs and have them move ...a bit. As Im not making a full on "physics game" it does seem like you might be right, but how would add a force to OTHER objects? put the code on them instead? an on collide kind of thing?

Feb 03, 2013 at 01:05 AM markfrancombe

Yup, something like //pseudocode
OnCollisionEnter() { if (hit.collider.rigidbody){hit.collider.rigidbody.AddForce} }

Feb 07, 2013 at 04:21 AM schaddemm
(comments are locked)
10|3000 characters needed characters left

Hi, this is an old question, but still, I'll write my opinion, if anyone ever bumps into this question.

First of all, I'm new to Unity, and am trying to learn what I can about rigidbodies and character controllers. But you could change your character from character controller to rigidbody and program it's movements. That way, when you bump into something which is also a rigidbody, it'll bounce off naturally.

If you don't want that, you can (I'm not sure if this will work) detect the collision through script then use Rigidbody.AddForce(), but that would be a pain, since 1) I don't know if you can detect collisions between character controller and rigidbody, 2) You would have to do that to every object in the game, which is not viable, 3) The force you'd have to apply would depend on the character's speed. Please correct me if I'm wrong, since I'm new to Unity.

Overall, I'd reccomend you use rigidbody on your character, instead of character controller. Most of the physics calculations are made for you.

more ▼

answered Sep 15, 2013 at 12:07 AM

ZaninDevelopper gravatar image

ZaninDevelopper
1

(comments are locked)
10|3000 characters needed characters left

If you want to push Rigidbodies or objects with the Character Controller, you can apply forces to any object that it collides with via the OnControllerColliderHit() function through scripting.

This is a direct quote from the Character Controller information page on this site: http://docs.unity3d.com/Documentation/Components/class-CharacterController.html

more ▼

answered Dec 01, 2013 at 10:17 PM

arcanealchemy gravatar image

arcanealchemy
0

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3181
x849

asked: Feb 02, 2013 at 09:10 PM

Seen: 4870 times

Last Updated: Dec 01, 2013 at 10:17 PM