Jumping part is in Blue, Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
public Transform groundcheck;
public CharacterController controuler;
public float jumphigh;
public float movingspeed;
public float currentspeed = 0f;
public float timetocometostop = 50f;
public float gravity = 10f;
public float checkradius = 0.5f;
public LayerMask la;
float currentgrafyty;
bool ismoving = false;
Vector3 dir;
float currentdirectionx;
float currentdirectiony;
Vector3 velocety;
public bool isgrounded = false;
// Update is called once per frame
void Update()
{
isgrounded = Physics.CheckSphere(groundcheck.position, checkradius, la);
//basic movement
if(Input.GetKey(“w”) || Input.GetKey(“s”) || Input.GetKey(“a”) || Input.GetKey(“d”) && currentspeed != movingspeed)
{
controuler.Move(dir * currentspeed * Time.deltaTime);
float x = Input.GetAxisRaw(“Horizontal”);
float y = Input.GetAxisRaw(“Vertical”);
currentdirectionx = x;
currentdirectiony = y;
dir = transform.right * x + transform.forward * y;
ismoving = true;
if(ismoving == true)
{
currentspeed += timetocometostop * Time.deltaTime;
}
}
else if (currentspeed >= 0f)
{
dir = transform.right * currentdirectionx + transform.forward * currentdirectiony;
controuler.Move(dir * currentspeed * Time.deltaTime);
ismoving = false;
if (ismoving == false)
{
currentspeed -= timetocometostop* Time.deltaTime;
}
}
if(currentspeed <= 0f)
{
currentspeed = 0f;
}
if(currentspeed >= movingspeed)
{
currentspeed = movingspeed;
}
//basic movement end
//Jumping
if (Input.GetButton(“Jump”) && isgrounded == true)
{
Debug.Log(“Jump”);
currentgrafyty += jumphigh;
}
//Jumping end
//velocety
if(isgrounded == false)
{
currentgrafyty -= gravity * Time.deltaTime;
}
else
{
currentgrafyty = 0f;
}
velocety = transform.up * currentgrafyty;
controuler.Move(velocety * Time.deltaTime);
//velocety end
}
}