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!