# Why does my capsule collider fall without my object (Unity)?

I've got a player with a rigidbody/capsule collier (gravity enabled) and a plane with a box collider. When the player is on the plane, everything works as expected, the player can walk across the plane with no issue. However, when the player walks off the plane, I want the player to fall. However, what happens instead is that the capsule collider falls but the player just keeps walking in thin air. Why is this happening?

Problem:

Colliders setup:

Code:

void Update () {
i = 0.1f;
transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + i);
}


Sorry if I'm doing something stupid, I'm new to game development/Unity, I usually program other things, not 3D games. Just expiermenting a bit to learn.

In your code you are moving the transform forward and keeping the y value the same at each call to Update(). By doing this your transform cannot drop because the y value is being reset at each call to Update(). A better way to move your character forward would be like this:

transform.position += transform.forward * Time.deltaTime * movementSpeed;

• Out of curiosity, would applying a force to my rigidbody be an appropriate movement system? – Ashwin Gupta Oct 31 '16 at 5:25
• @AshwinGupta It is better to move it as I have shown above unless it is for short spurts of movement. Continuous movement is best to have complete control over. If you apply force to a rigidbody for movement then you are basically doing one thing and waiting for the physics engine to handle the rest of the movement. It is really up to you and how you are wanting the behavior to be though. – saboehnke Oct 31 '16 at 13:48
• ok thanks. That makes sense, I implemented your answer and it works great. – Ashwin Gupta Oct 31 '16 at 15:33
• @AshwinGupta Good to hear! – saboehnke Oct 31 '16 at 19:05

Welcome to game development world. First of all I suggest to you not to move the player changing the transform values by code. Because, as you can see that can produce weird behaviours. So you have to use the Translate function. I will give you a really good resource, where you can read how to program a really cool control system and learn a bit of the "modus operandi" in Unity.