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

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?

Colliders setup:

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.


Answer 1:

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;

Answer 2:

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.