# Character Controller not resetting flags correctly?

**URL:** https://discussions.unity.com/t/character-controller-not-resetting-flags-correctly/419102
**Category:** Physics
**Created:** [July 26, 2010, 8:51pm UTC](https://discussions.unity.com/t/character-controller-not-resetting-flags-correctly/419102 "2010-07-26T20:51:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![TrialByFun](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/trialbyfun/32/436950_2.png) [@TrialByFun](https://discussions.unity.com/u/TrialByFun)
#### Post date: [July 26, 2010, 8:51pm UTC](https://discussions.unity.com/t/character-controller-not-resetting-flags-correctly/419102/1 "2010-07-26T20:51:29Z")

</div>

I was going to report this as a bug, but i want to make sure that i’m not doing anything stupid first.

I have a very simple scene with a character collider and a movement script.

```auto
private var controller : CharacterController;
var velocity : Vector3;
private var playerGravity : Vector3 = Vector3(0,-30,0);
private var jumpVel : float = 10.0;

function Start()
{
	controller = GetComponent(CharacterController);
}
var flags : CollisionFlags = 0;;
var timeColliding : float = 0;
function Update () {

	// move right 1m a second;
    velocity.x += 1 * Time.deltaTime;
    
    // apply player gravity
	velocity += playerGravity * Time.deltaTime;
	
	// move the controller
	flags = controller.Move(velocity * Time.deltaTime);
	
	// Respond to any collision we might have had
	if((flags CollisionFlags.CollidedBelow) != 0)
	{
		velocity.y = jumpVel;//0;
		
		// just making sure the problem is only for hitting your head
		timeColliding = 0;
		
	}
	
	if ((flags CollisionFlags.CollidedAbove) != 0)
	{
        velocity.y = 0; //-jumpVel;
        
        // increment collide timer
        timeColliding += Time.deltaTime;
    }
}

```

The script is set to make the controller to bounce up when it hits the ground, and then lose velocity and fall normally when it hits the ceiling.

The bounce on the ground part works fine however, on colliding above, the controller moves very slowly down for over a second and then starts falling normally.

What appears to be happening is that CollidedAbove flag seems to be set for a long time after the controller itself has moved away from the object it hit. ( i’ve set a variable called TimeColliding so you can see whats happening)

As a test I tried mirroring gravity and flipping the jumpVel values. The Behaviour was as I expected, which further points to the CollidedAbove flag.

As an additional note, this only happens when the velocity.x is greater than 0;

I have attached a package file to this post.

Any help appreciated.

[354554–12330–$controllerproblem\_209.unitypackage](https://discussions.unity.com/uploads/short-url/1mYjVrgUYCIa1SgjtTeoQRfiDgH.unitypacka) (5.87 KB)

---

<div class="post-metadata">

### Author: ![j\_y\_k](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@j\_y\_k](https://discussions.unity.com/u/j_y_k)
#### Post date: [July 26, 2010, 9:43pm UTC](https://discussions.unity.com/t/character-controller-not-resetting-flags-correctly/419102/2 "2010-07-26T21:43:26Z")

</div>

I recall observing the behavior you describe when trying to tweak the FPS controller so that the controller would ‘bounce’ off of ceilings instead of ‘sticking’ to them. I got the same results that you describe here, and ended up working around it by zeroing the y velocity only when a collision from above was detected _and_ the y velocity was already greater than zero.

As for the behavior itself, I imagine it can be traced back to how PhysX handles things internally, but I don’t know why it behaves that way exactly, or if it’s something that could be changed or fixed.

---

<div class="post-metadata">

### Author: ![TrialByFun](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/trialbyfun/32/436950_2.png) [@TrialByFun](https://discussions.unity.com/u/TrialByFun)
#### Post date: [July 27, 2010, 11:50am UTC](https://discussions.unity.com/t/character-controller-not-resetting-flags-correctly/419102/3 "2010-07-27T11:50:55Z")

</div>

Thanks for the tip Jesse, i’ll give it a try and post back if it works. 😄

I’m not convinced this is a PhysX thing, mainly because setting gravity to go upwards and then mirroring the jumpvels (so in essence you are jumping off the ceiling and banging your head on the floor) does not cause this problem to happen.

So I’m guessing its something to do with the CharacterController.Move() function.

Still worth putting a bug in?

---

<div class="post-metadata">

### Author: ![TrialByFun](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/trialbyfun/32/436950_2.png) [@TrialByFun](https://discussions.unity.com/u/TrialByFun)
#### Post date: [July 28, 2010, 9:14am UTC](https://discussions.unity.com/t/character-controller-not-resetting-flags-correctly/419102/4 "2010-07-28T09:14:06Z")

</div>

Your suggestion worked perfectly, thanks Jesse!
