Rigidbodies Do's and Don'ts

Hi all,

I am real confused over this! :slight_smile:

Firstly a character controller is a ‘special’ type of rigid body yes?, i.e. it can affect physics but not be affected and also has no gravity etc. Yet you can attach a rigid body to the same object; what would be the point of that?

Secondly, I assumed :face_with_spiral_eyes: that you were never meant to directly alter a rigid bodies transform without going through add force/torque etc. Yet I see in many code examples and responses things like:

rigidbody.transform.eulerAngles=new Vector3(0,100.1f,0);

Isn’t this bad? - out of interest whats the correct way to set an exact angle on a rigid body (assuming the above is bad!)

thanks in advance

I’m sure you’ll find your answer here:

Unity doc

Character controller is not a really component, because Unity made a script to control a character for FPS (with basic movements).

Hi,

Yes I read that. It’s confusing when though you see example source code that seems to go against the doc’s.

thanks

BTW you can use rigidbody with isKinematic activated, to reproduce a not real movement (using transform).

Hi,

I can’t use isKinematic because I need to have the object stop/react with the scenery. It’s proving to be very difficult and I see many people ask a similar question but no real answers :frowning:

thanks

You can activate/desactivate by scripting this option. Depends on events on your game.
The Unity example is a good one.
“When a character dies, turn off this option and it will act as a ragdoll”.

So you can use transform to rotate exactly your character. And also when it’s necessary, use force to move it.

But you’re right, documentation is not clear enough…

Thanks cayou66,

But that’s no good to change states is it?
Basically I need to orientate/move my rigid body and have it stop when it hits physics. I can’t therefore have is kinematic on; as I need the physic. At the moment (though bad!) I am directly altering the euler angles and velocity to get the movement I want even though it’s not a kinematic body.
Essentially I have a character controller body that I wish to pull/push a crate. The crate therefore needs to stop when it hit’s something (and indeed signal the character controller to stop also). I thought this would be quite trivial but it ain’t!! :slight_smile:

Cheers

EDIT: suppose you are rotating the cube (because your player is touching it - hence moving it). The cube hits the corner of the scenery; the cube needs to stop rotating and so does the player. hence physics (i.e. not kinematics) are needed all the time. I did look at sweeptest but that seems very unreliable even on a scene where nothing is moving!

Does the movements needs to be realistic?
In these case, personnaly I never use rigidbody with forces. I check all the collision and stop moving objects" by hand".
It’s like differences between arcade and simulation games. What’s yours?

Thanks.
No, not after realism at all :slight_smile:
Think of Wii Zelda and you get the idea of what I am trying to do with the push/pull crate.
With kinematic’s on; it would be a breeze BUT (of course) you can push the crate straight into the scenery!!; I tried ray cast and sweeptest (i.e. before we commit to the move check if we can actually do it) and it would seem a kinematic body doesn’t produce a result. Equally the character collider (potentially attached to the crate) could swing round and also go through the scenery. Of course making all the scenery rigid bodies would give some collision detection but that’s insane!.
Been on this days and struggling.
Please enlighten me how you check collisions in a reliable way.

Cheers

you got it wrong, you can use IsKinematic, the thing holding you not to go trough other objects and environment is the Collider. and since you already have a rigidbody on your gameobject, it can influence by Physics other gameobjects. it’s just that other gameobjects does not influence your gameobject.

So i recommend using IsKinematic, if you don’t want your player to be hit by a giant barrel at a very high velocity and with a mass greater than 10x player’s rigidbody mass => your player will be nothing more than a rubber ball in the environment bouncing all over the place because of the impulse the barrel applies to it. (physics 101)

Hey ar0nax,

:slight_smile: ; I’m obviously doing it wrong then (I’m a newbie to Unity incase you couldn’t guess).
According to the docs a kinematic body does not react to physics (and this seems to be true) i.e. it goes through the scenery 9though I agree it has a collider so shouldn’t). Hence why really (if I use kinematics) I need to collision check real-time (i.e. ray/sweep) at that point to determine a collision would occur or not.
It’s an easy example to setup and see the problems :slight_smile:

Cheers and thanks

Make sure the collider on your player has IsTrigger unchecked, and so must the environment mesh collider, if you have one, also note that if your environment has a mesh collider, your player must havea primitive collider (box, sphere etc).

All i was saying is that if you want to be able to move crates around with your character you do not need it’s rigidbody to be nonKinematic. and collision detection is done between colliders automatically.

so…make sure none of the interacting objects has it’s collider’s IsTrigger checked, and they all have rigidbodies with alower mass than the player’s rigidbody,so the player won’t bounce back too much from the impact.

also you can check Edit->Project Settings->Physics to make sure your options there are reasonable (bounce, min penetration penalty etc)

Hey ar0nax,

My player is a character collider so doesn’t have an ‘is trigger’ option. i.e. it can’t have another collider attached.
My scenery are just cube’s with cube colliders sat on a flat floor (which is a mesh); cube’s have no rigid bodies attached (and I don’t want them to).
Player’s cube (to push) is a rigid body with kinematics enabled for now.

I’m obviously completely missing some rather important point here ( :wink: )

thanks

EDIT: basically if I move a kinematic body it goes straight through any colliders that don’t have rigid bodies attached.

Markhula, I’m fairly new to Unity as well… I can’t directly help you with your problem, but I wanted to refer you to the 3rd person platformer tutorial at Unity Customer Service: Technical Support & Training | Unity

It explains the Is Trigger option and you set up a character with a collider. If you haven’t done it I recommend that you do.

Hi Ender,

Triggers no good :slight_smile:
In the doc’s it state’s it may not be called each frame.
Also I need to deal with my collision before it occurs hence the sweep test and then decide whether it would result in a collision or not based on that.
Hope you are enjoying Unity ; there’s an absolute TON to learn :slight_smile:

Cheers