Whenever my player walks into a collider, it gets stuck and continues to walk forward over and over again. Any effort to get it to stop or to move away from it go ignored. I’ve tried everything I can think of to fix the issue but am not experienced enough in engine to figure it out on my own and I can’t seem to Google the right phrases/questions to get what I need.
I’ve tried different colliders, I’ve tried enabling interpolate, etc. It does not stop it from sticking.
Maybe try to set the collision detection on continuous in the rigidbody of the player
And to prevent the player from sticking make a new material without friction and drag it onto the rigidbody.
Wait I watched your linked video and I think its not really beginner friendly. Also if i am seeing this right the player doesn’t have a collider? If that is the case dont go further with this tutorial. For example of you have a scene with a player that has a collider and a wall with a collider they already collide with eachother and you dont need any programming for that. Now he uses functions and stuff. I recommend you watching brackeys they explain things very clear and the right way.
I decided to make a new Player Controller script with a different code. Something about the tutorial’s code is making it do that - unsure what but it’s not worth the headache. Here’s what I’m using now if you want it. The player still jitters when colliding repeatedly but doesn’t get stuck
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float movSpeed;
float speedX, speedY;
Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
speedX = Input.GetAxisRaw("Horizontal") * movSpeed;
speedY = Input.GetAxisRaw("Vertical") * movSpeed;
rb.velocity = new Vector2(speedX, speedY);
}
}
Honestly I have no idea, you can maybe try to test in a blank scene where you have a ground and square as the player that will both have a collider and the player a rigidbody and your movement script and compare your game with that scene maybe you will see something. Your movement script looks nice!
That is the worst playercontroller cript I have seen yet, and I have seen quite a few! I can see that it’s the same thing as the video is doing from jumping through it. I don’t have the time to watch all the way too see if the author has some reason to do things in a weird way, but;
Do not start a coroutine in Update every frame to move you until you hit the target position! That will a) mean that you will get stuck forever if you walk into a wall and b) mean that you get stuck if you press left and then up on the next frame.
The code @sagemdeleon posted is a sensible beginners player controller. It’s a ton simpler, and everything in there is sensible, so go with that.