noob question: FPC collision

Sorry to bother you with something simple like that but it drives me crazy:

I can’t get my FPC to collide with a simple box and push it away.

I got the standard FPC on a plane. On top of that there’s a cube with a rigidbody component and a box collider.
Then I add a rigidbody to the first layer of the FPC - right?

But that damn cube just won’t move…

I’ m so embarassed :sweat_smile:

Nope, the character controller isn’t designed for interacting with physics like that. There are a couple of physics-controlled first-person scripts on the wiki that you can experiment with instead. Don’t be embarrassed…stuff like that isn’t super-obvious at first. :slight_smile:

–Eric

Uhhhh ?

So the FPC from the Standard Assets folder doesn’t work !??

Ooooookay… that is pretty mean then
:wink:

Thanks :smile:

Or you could try this FPSController script instead of the default one and you will be able to push rigidbodys.

var speed = 6.0;
var jumpSpeed = 8.0;
var pushPower = 0.5;
var gravity = 20.0;

private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
private var controller : CharacterController;
function Start () {
	controller = GetComponent (CharacterController);
}

function FixedUpdate() {
	if (grounded) {
		// We are grounded, so recalculate movedirection directly from axes
		moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
		moveDirection = transform.TransformDirection(moveDirection);
		moveDirection *= speed;
		
		if (Input.GetButton ("Jump")) {
			moveDirection.y = jumpSpeed;
		}
	}

	// Apply gravity
	moveDirection.y -= gravity * Time.deltaTime;
	
	// Move the controller
	var flags = controller.Move(moveDirection * Time.deltaTime);
	grounded = (flags  CollisionFlags.CollidedBelow) != 0;
}

function OnControllerColliderHit (hit : ControllerColliderHit) {
	var body : Rigidbody = hit.collider.attachedRigidbody;
	if (body == null || body.isKinematic)
		return;
	if (hit.moveDirection.y < -0.3)
		return;
	var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
	body.velocity = pushDir * pushPower;
}

Your FPC doesn’t need a rigidbody component with this script.

It works fine. :slight_smile: In most cases with FPS games, you generally don’t want to physically affect everything you come into contact with.

–Eric

Okay, I only have some pieces of furniture to push around …

You guys made my day - thanks a lot !!