My rigidbody player that I made keeps on getting stuck on walls if I jump and hold the direction key on the wall and I dont know how to fix it.
Here is the code I am using, mostly a mash up of code I used from tutorials because I am not an experienced programmer.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
/////////////////////
////variable zone////
/////////////////////
public Rigidbody playerBody;
private Vector3 inputVector;
public float speed = 10f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
private bool isGrounded;
public float jumpHeight = 3f;
/////////////////////
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
inputVector = new Vector3(Input.GetAxis("Horizontal") * speed * 20 * Time.deltaTime, playerBody.velocity.y, Input.GetAxis("Vertical") * speed * 20 * Time.deltaTime);
transform.LookAt(transform.position + new Vector3(inputVector.x, 0, inputVector.z));
playerBody.velocity = inputVector;
if(Input.GetButtonDown("BlobbyJump") | Input.GetButtonDown("AllJump") && isGrounded)
{
playerBody.AddForce(Vector3.up * jumpHeight, ForceMode.Impulse);
}
}
}