how do i make my player fall off platforms because when i go off a platform i just fly

when was making a script the let my player move around but the player wouldn’t fall the player would fly around and i can make it fall the script is:

using UnityEngine;
using System.Collections;

public class movearownd : MonoBehaviour {

   public float movespeed = 10;
   public float rotatespeed = 20;

   // Use this for initialization
   void Start () {
 
   }

   // Update is called once per frame
   void Update () {
     float moveforward = movespeed * Time.smoothDeltaTime * Input.GetAxis("Vertical");
   	 float rotateLeft = movespeed * Time.smoothDeltaTime * Input.GetAxis("Horizontal");
     float rotate = rotatespeed * Time.smoothDeltaTime * Input.GetAxis("Horizontal");
	
	 transform.Translate(Vector3.forward * moveforward);
	 //transform.Translate(Vector3.left * moveLeft);
	 transform.Rotate(Vector3.up, rotate);
   }
}

can u edit the script so the player can fall

ref:_00D20M42f._50020MFICg:ref

There are lots of ways to go about this. But before I tell you those, aroud is not spelled with a W :stuck_out_tongue:

One easy way is using the character controller that comes with unity to control your character, because you can just use gravity and such, that already can tell if he walks off a ledge.

Or if you need your own solution, you could do checks to see if the player has no ground below him, such as raycasting straight down, and if it hits nothing, then fall by applying forces down on your player. I wont write this code for you… but its like this (no this wont work if you paste it lol)

private Ray ray;
private Raycasthit hit;
private Vector3 down = Vector3.down;

void Update()
{
if (Physics.Raycast (transform.position, down, 2)) {
print (“No Ground Below Player! Fall Logic HERE!”);
}

Orrr… maybe if your player has a rigidbody, then have him “use gravity” in the inspector if thats not set…

You can either attach a rigid body component to the player object, enable gravity and then use physics (maybe via a character controller) to move it around, or you can add something like

if(!collidingWithGround)
    transform.translate(-Vector3.up * gravityConstant);

in your update function and handle the collision detection manually somewhere else.