Hi, how might I make a see-saw type object be affected by a character controller?
I can make the see-saw rotate/turn by dropping a rigid body onto it, but character controller seems to have no weight? Is there a way to add weight to a character controller? Or is there a better way to do this?
Character Controllers do not by design interact with the physics engine except for collisions. To apply forces you have to add a script. The best way would be to take the PushRigidbodyScript (Posted Below) and use Rigidbody.AddForceAtPoint() to add negative force at the point where the controller hits the see-saw.
// this script pushes all rigidbodies that the character touches
var pushPower = 2.0;
function OnControllerColliderHit (hit : ControllerColliderHit) {
var body : Rigidbody = hit.collider.attachedRigidbody;
// no rigidbody
if (body == null || body.isKinematic)
return;
// We dont want to push objects below us
if (hit.moveDirection.y < -0.3)
return;
// Calculate push direction from move direction,
// we only push objects to the sides never up and down
var pushDir : Vector3 = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
// If you know how fast your character is trying to move,
// then you can also multiply the push velocity by that.
// Apply the push
body.velocity = pushDir * pushPower;
}
then you would need to make a few minor adjustments to the code. This should work pretty well. It isn't perfect, just an example of how you should probably do it.
// this script pushes all rigidbodies that the character touches
var pushPower = 2.0;
function OnControllerColliderHit (hit : ControllerColliderHit) {
var body : Rigidbody = hit.collider.attachedRigidbody;
// no rigidbody
if (body == null || body.isKinematic)
return;
// Calculate push direction from move direction,
var pushDir : Vector3 = hit.moveDirection;
// If you know how fast your character is trying to move,
// then you can also multiply the push velocity by that.
// Apply the push
body.AddForceAtPosition(hit.point, pushDir);
}