Hello everyone,

really a lot of Ty for this site and this great work you've been doing here.

the thing is I've started my project a few months ago and am starting slowly and thanks god who led me to this great site since i was looking to code/learn how to make stable control.

so straight to the point I've done everything just fine and i just finished the sliding bit on :
Creating a Custom 3rd-Person Character and Camera System with C#

but I've noticed that's my character was flying so i tried almost everything i know but nothing changed even siting the gravity from the Rigidbody did nothing it actually mad my character flipping around when i move, I've started a new Scene from scratch to see if it was my map or something and I've imported the same scripts but the same thing happened again.

here is my Character look like:

prntscr.com/eo5aqo

BTW: there is gravity after jumping but he returns to the same place in-air and i did change the character same thing happened too.


TController
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TController : MonoBehaviour
{
    public static CharacterController CharacterController;
    public static TController Instance;
    
	void Awake()
    {
        CharacterController = GetComponent("CharacterController") as CharacterController;
        Instance = this;
        TCamera.UseExistingOrCreateNewMainCamera();

	}
	
	void Update ()
    {
		if (Camera.main == null) // Video 6 on 3DBuzz Site
            return;

        GetLocomotionInput();
        HandleActionInput();

        TMotor.Instance.UpdateMotor();
	}

    void GetLocomotionInput() // for Dead zone
    {
        var deadZone = 0.1f; // if with game pad we can switch to public

        TMotor.Instance.VerticalVeclocity = TMotor.Instance.MoveVector.y; // Vid 3 in 3rd part
        TMotor.Instance.MoveVector = Vector3.zero;

        if (Input.GetAxis("Vertical") > deadZone || Input.GetAxis("Vertical") < -deadZone)
            TMotor.Instance.MoveVector += new Vector3(0, 0, Input.GetAxis("Vertical"));

        if (Input.GetAxis("Horizontal") > deadZone || Input.GetAxis("Horizontal") < -deadZone)
            TMotor.Instance.MoveVector += new Vector3(Input.GetAxis("Horizontal"), 0, 0);
    }

    void HandleActionInput()
    {
        if (Input.GetButton("Jump"))
        {
            Jump();
        }
    }

    void Jump()
    {
        TMotor.Instance.Jump();
    }

}
TMotor
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TMotor : MonoBehaviour
{
    public static TMotor Instance;

    public float MoveSpeed = 10f;
    public float JumpSpeed = 6f;
    public float Gravity = 21f;
    public float TerminalVelocity = 20f;
    public float SlideThreshold = 0.6f;
    public float MaxControllableSlideMagnitude = 0.4f;

    private Vector3 SlideDirection;

    public Vector3 MoveVector { get; set; }
    public float VerticalVeclocity { get; set; }

	void Awake()
    {
        Instance = this;
	}
	
	public void UpdateMotor()
    {
        SnapAlignCharacterWithCamera();
        ProcessMotion();
    }
    void ProcessMotion()
    {
        MoveVector = transform.TransformDirection(MoveVector); // Transform MoveVector to world Space

        if (MoveVector.magnitude > 1)        // Normalize MoveVector if it's greater than 1
            MoveVector = Vector3.Normalize(MoveVector);

        ApplySlide();  // Apply Sliding if avilable

        MoveVector *= MoveSpeed; //multiply MoveVector by MoveSpeed

        MoveVector = new Vector3(MoveVector.x, VerticalVeclocity, MoveVector.z); // reaplly VerticalVelocity to MoveVector.y

        ApplyGravity();  // apply gravity

        // move Character in World
        TController.CharacterController.Move(MoveVector * Time.deltaTime);
    }

    void ApplyGravity ()
    {
        if (MoveVector.y > -TerminalVelocity)
            MoveVector = new Vector3(MoveVector.x, MoveVector.y -Gravity *Time.deltaTime, MoveVector.z);

        if (TController.CharacterController.isGrounded && MoveVector.y < -1)
            MoveVector = new Vector3(MoveVector.x, -1, MoveVector.z);
    }

    void ApplySlide()
    {
        if (!TController.CharacterController.isGrounded)
            return;

        SlideDirection = Vector3.zero;

        RaycastHit hitInfo;

        if (Physics.Raycast(transform.position + Vector3.up, Vector3.down, out hitInfo))
        {
            if (hitInfo.normal.y < SlideThreshold)
                SlideDirection = new Vector3(hitInfo.normal.x, -hitInfo.normal.y, hitInfo.normal.z);
        }

        if (SlideDirection.magnitude < MaxControllableSlideMagnitude)
            MoveVector += SlideDirection;

        else
        {
            MoveVector = SlideDirection;
        }

    }

    public void Jump()
    {
        if (TController.CharacterController.isGrounded)
            VerticalVeclocity = JumpSpeed;
    }

    void SnapAlignCharacterWithCamera()
    {
        if (MoveVector.x !=0 || MoveVector.z !=0) //Class 9
        {
            transform.rotation = Quaternion.Euler(transform.eulerAngles.x,
                                       Camera.main.transform.eulerAngles.y,
                                                   transform.eulerAngles.z);
        }
    }
}
TCamera
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TCamera : MonoBehaviour
{
    public static TCamera Instance;

    public Transform TargetLookAt;

    public float Distance = 5f;
    public float DistanceMin = 3f;
    public float DistnaceMax = 10f;
    public float DistanceSmooth = 0.05f;
    public float X_MouseSensitivity = 5f;
    public float Y_MouseSensitivity = 5f;
    public float MouseWheelSensitivity = 5f;
    public float X_Smooth = 0.05f;
    public float Y_Smooth = 0.1f;
    public float Y_MinLimit = -40f;
    public float Y_MaxLimit = 80f;
    
    private float mouseX = 0f;
    private float mouseY = 0f;
    private float velX = 0f;
    private float velY = 0f;
    private float velZ = 0f;
    private float velDistance = 0f;
    private float startDistnace = 0f;
    private Vector3 postion = Vector3.zero;
    private Vector3 desiredPostion = Vector3.zero;
    private float desiredDistance = 0f;

    void Awake()
    {
        Instance = this;
    }

	void Start ()
    {
        Distance = Mathf.Clamp(Distance, DistanceMin, DistnaceMax);
        startDistnace = Distance;
        Reset();
	}
	
	void LateUpdate ()
    {
        if (TargetLookAt == null)
            return;

        HandlePlayerInput();

        CalculateDesiredPostion();

        UpdatePostion();
	}

    void HandlePlayerInput()
    {
        var deadZone = 0.01f;
        if (Input.GetMouseButton(1)) // now the key for the mouse orbit around the player which is RMB
        {
            mouseX += Input.GetAxis("Mouse X") * X_MouseSensitivity;
            mouseY -= Input.GetAxis("Mouse Y") * Y_MouseSensitivity;

        }

        mouseY = Helper.ClampAngle(mouseY, Y_MinLimit, Y_MaxLimit);         // Limit mouseY at Video 18

        if (Input.GetAxis("Mouse ScrollWheel") < -deadZone || Input.GetAxis("Mouse ScrollWheel") > deadZone) // DeadZone area
        {
            desiredDistance = Mathf.Clamp(Distance - Input.GetAxis("Mouse ScrollWheel") * MouseWheelSensitivity
                                                                         , DistanceMin, DistnaceMax);
        }
    }

    void CalculateDesiredPostion()
    {
        // evaluate the distance
        Distance = Mathf.SmoothDamp(Distance, desiredDistance, ref velDistance, DistanceSmooth);

        // calc the desired postion
        desiredPostion = CalculatePostion(mouseY, mouseX, Distance);
    }

    Vector3 CalculatePostion(float rotationX, float rotationY, float distance)
    {
        Vector3 direction = new Vector3(0, 0, -distance);
        Quaternion rotation = Quaternion.Euler(rotationX, rotationY, 0);
        return TargetLookAt.position + rotation * direction;
    }

    void UpdatePostion()
    {
        var posX = Mathf.SmoothDamp(postion.x, desiredPostion.x, ref velX, X_Smooth);
        var posY = Mathf.SmoothDamp(postion.y, desiredPostion.y, ref velY, Y_Smooth);
        var posZ = Mathf.SmoothDamp(postion.z, desiredPostion.z, ref velZ, X_Smooth);
        postion = new Vector3(posX, posY, posZ);

        transform.position = postion;

        transform.LookAt(TargetLookAt);

    }

    public void Reset()
    {
        mouseX = 0;
        mouseY = 10;
        Distance = startDistnace;
        desiredDistance = Distance;
    }

    public static void UseExistingOrCreateNewMainCamera()
    {
        GameObject tempCamera;
        GameObject targetLookAt;
        TCamera myCamera;

        if (Camera.main !=null)
        {
            tempCamera = Camera.main.gameObject;
        }
        else
        {
            tempCamera = new GameObject("Main Camera");
            tempCamera.AddComponent<Camera>();
            tempCamera.tag = "MainCamera";
        }

        tempCamera.AddComponent<TCamera>();
        myCamera = tempCamera.GetComponent("TCamera") as TCamera;

        targetLookAt = GameObject.Find("targetLookAt") as GameObject; // this part is in video 14

        if (targetLookAt == null)
        {
            targetLookAt = new GameObject("targetLookAt");
            targetLookAt.transform.position = Vector3.zero;
        }

        myCamera.TargetLookAt = targetLookAt.transform;
    }
}