using System.Collections;
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
Vector2 movementInput;
public float moveSpeed = 1f;
public float collisionOffset = 0.05f;
Rigidbody2D rb;
public ContactFilter2D movementFilter;
List<RaycastHit2D> castCollisions = new List<RaycastHit2D>();
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate() {
if (movementInput != Vector2.zero)
{
bool success = TryMove(movementInput);
if (!success)
{
success = TryMove(new Vector2(movementInput.x, 0));
if (!success)
{
success = TryMove(new Vector2(0, movementInput.y));
}
}
}
}
private bool TryMove(Vector2 direction)
{
int count = rb.Cast(
direction,
movementFilter,
castCollisions,
moveSpeed * Time.fixedDeltaTime + collisionOffset);
if (count == 0)
{
rb.MovePosition(rb.position + direction * moveSpeed * Time.fixedDeltaTime);
return true;
}
else
{
return false;
}
}
void OnMove(InputValue movementValue)
{
movementInput = movementValue.Get<Vector2>();
}
}
what i’m trying to do is to make a character slide off when it hits with a collider. And theres this thing that the line " success = TryMove(new Vector2(0, movementInput.y));" says that the unused value assignment; any tips? dont change the code significantly tho, thanks