Simple Move Error- Character Flying off map

Hi there,

I am implementing multiplayer to my game using Quill18’s Unity/Photon tutorial. I have deleted the standard character motor that comes with Unity and have added a new movement script that works with the animations. This script is based on one of these tutorials.

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
	
	/*
	 * 
	 * 				This component is only enabled for "my player" (i.e. the character belonging to the local client machine)
	 * 
	 * 
	 */
	
	float speed = 10f;
	float jumpSpeed = 6f;
	Vector3 direction = Vector3.zero;	// forward/back & left/right
	float   verticalVelocity = 0;
	
	CharacterController cc;
	Animator anim;
	CapsuleCollider capsCollider;
	float realCapsuleColliderHeight = 2f;
	float jumpCapsuleColliderHeight = 1.2f;
	
	
	
	// Use this for initialization
	void Start () {
		cc = GetComponent<CharacterController>();
		anim = GetComponent<Animator>();
		capsCollider = (CapsuleCollider)collider;
	}
	
	// Update is called once per frame
	void Update () {
		
		// WASD forward/back & left/right movement is stored in "direction"
		direction = transform.rotation * new Vector3( Input.GetAxis("Horizontal") , 0, Input.GetAxis("Vertical") );
		
		if(direction.magnitude > 1f) {
			direction = direction.normalized;
		}
		
		anim.SetFloat("Speed", direction.magnitude);
		
		// Handle Jumping
		
		if(cc.isGrounded) {
			anim.SetBool("Jumping", false);
			//capsCollider.height = realCapsuleColliderHeight;
			
			if(Input.GetButton("Jump")) {
				verticalVelocity = jumpSpeed;
			}
			else {
				verticalVelocity = -1f;
			}
		}
		else {
			anim.SetBool("Jumping", true);
			//capsCollider.height = jumpCapsuleColliderHeight;
		}
		
		
	}
	
	// FixedUpdate is called once per physics loop
	// Do all MOVEMENT and other physics stuff here.
	void FixedUpdate () {
		
		Vector3 dist = direction * speed * Time.deltaTime;
		
		if(cc.isGrounded) {
		}
		else {
			verticalVelocity += Physics.gravity.y * Time.deltaTime;
		}
		
		Debug.Log (verticalVelocity);
		
		dist.y = verticalVelocity * Time.deltaTime;
		
		cc.Move( dist );
	}
}

The character spawns fine, but immediately movies upwards and won’t stop ascending. When I press the WASD keys the animations seem to work fine, I’m not sure if movement is working correctly as I am rapidly ascending. After removing the script the animations don’t play but the player stays on the ground. I have disabled all other colliders besides the character controller. Any help would be greatly appreciated. More details can be provided if needed.

Probably a gravity problem.
Try doing

verticalVelocity -= Physics.gravity.y * Time.deltaTime;

instead of

 verticalVelocity += Physics.gravity.y * Time.deltaTime;

at line 75 of your script.