My Player won't move after a collision.

Hi!
I recently started using Unity and I am following a tutorial online. However, I recently discovered after my character hit a tile collider it no longer works. My code is posted below if anyone can help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
Vector2 movementInput;
Rigidbody2D rb;
public float moveSpeed = 1f;
public ContactFilter2D movementFilter;
List castCollisions = new List();
public float collisionOffset = 0.05f;

// Start is called before the first frame update
void Start()
{
rb = GetComponent();
}

// Update is called once per frame

private void FixedUpdate()
{
if (movementInput != Vector2.zero)
{
int count = rb.Cast(
movementInput,
movementFilter,
castCollisions,
moveSpeed * Time.fixedDeltaTime * collisionOffset);
if (count == 0)
{
rb.MovePosition(rb.position + movementInput * moveSpeed * Time.fixedDeltaTime);
}
}

}
void OnMove(InputValue movementValue)
{
movementInput = movementValue.Get();
}
}
Thanks!

Please use code-tags when posting code and not plain-text. You can edit your post above to use these too.

Next, dumping code doesn’t describe what you have already done to debug it. What debugging have you done? If you’re not moving then it’ll be because you’re not asking for any moves etc. What debugging have you done to check to see if you are asking for a move? Nothing? If not then this is a good place to start on how to begin to do that: Unity - Manual: Debug C# code in Unity

So movement is never zero in the text above maybe. This is where you start to figure out why that is. Maybe because there’s always a hit where you are because you’re slightly overlapped so the cast isn’t a good method for this determination and/or your movement that is attempting to not overlap is failing.

moveSpeed * Time.fixedDeltaTime * collisionOffset → moveSpeed * Time.fixedDeltaTime + collisionOffset
Hope this helps

1 Like