The rigidbody2D bodytype is set to dynamic so I don’t understand why I’m getting the error. Essentially I want my gameobject to stop dead when I release the directional buttons. Thanks in advance for any help. Here’s my script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed;
private Rigidbody2D rb2d;
private void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(moveHorizontal, moveVertical);
rb2d.AddForce(movement * speed);
rb2d.velocity = Vector2.zero;
}
}