I keep trying to make smoother movement and jumping with a rigidbody but wither the jumping stops working or the movement isn’t smooth. And the charactercontroller is not working like I want it to.
private Vector3 move;
public float velY, gravity, jumpSpeed;
public BoxCollider col;
public float speed;
public Rigidbody playerR;
public static bool jumped;
public Joystick joystick;
public void Start()
{
jumpSpeed = 7;
gravity = 7;
speed = 4;
velY = 5;
}
void Update()
{
if (IsGrounded())
{
velY -= gravity * Time.deltaTime;
}
Vector3 move = Vector3.zero;
move.x = Input.GetAxisRaw("Horizontal") * speed;
move.y = velY;
move.z = Input.GetAxisRaw("Vertical") * speed;
if (joystick.InputDirection != Vector3.zero)
{
move.x = joystick.InputDirection.x * speed;
move.z = joystick.InputDirection.z * speed;
move.y = 0;
}
playerR.velocity = move;
}
public bool IsGrounded()
{
int layerMask = LayerMask.GetMask("Platform");
return Physics.CheckBox(col.bounds.center, new Vector3(col.bounds.center.x, col.bounds.min.y, col.bounds.center.z), col.transform.rotation, layerMask);
}