Hey all, I am trying to make a very simple game with my player being a cube, through some digging online I have found some code that works pretty great for movement, but I keep having one main problem:
Whenever my player cube runs into a wall, it sort of jitters through the wall and bounces around all crazy.
I have a rigidbody component on the player along with a box collider, but no amount of editing can seem to solve this for me. Any suggestions on a fix? Or where to go from here?
30 sec Video reference of my problem:
A screenshot of my player’s components: Imgur: The magic of the Internet
The code I am using for movement:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
void Update()
{
Vector3 moveDir = Vector3.zero;
moveDir.x = Input.GetAxis("Horizontal") * speed; // get result of AD keys in X
moveDir.z = Input.GetAxis("Vertical") * speed; // get result of WS keys in Z
// move this object at frame rate independent speed:
transform.position += moveDir * speed * Time.deltaTime;
}
}