Player moving though walls while pressing two keys
Hi, I placed a plane, some cubes with box collider and a capsule that is my player, attached to him a rigidbody, capsule collider and a script that contains this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody rb;
private Vector3 moveInput;
private Vector3 moveVelocity;
public float movementSpeed = 10f;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
moveInput = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0f, Input.GetAxisRaw ("Vertical"));
moveVelocity = moveInput.normalized * movementSpeed;
rb.MovePosition(rb.position + moveVelocity * Time.deltaTime);
}
}
Dunno why but if I stay next to a cube and press two keys at the same time I can pass through it, anyone knows how to solve this? thanks
EDIT: seems like decreasing movementSpeed solved the problem, but still a problem
Comment