I should start by saying that my game is a top-down view over a field with my player, the player moves when I give it the correct input but keeps going when I release the key and increasing the linear drag does not work, I think I need to apply some code to counteract it with another force, Does anyone have a snippet of code or some advice? Thank You. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed;
private Rigidbody2D rb2d;
void Start()
{
rb2d = GetComponent<Rigidbody2D> ();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
rb2d.AddForce(movement * speed);
}
}
,So my game is a top-down view of a '‘field’ with a squirrel on it (so far). WASD movement works but when I let go of the keys the character keeps going as if it is on ice, How can I fix this? Is there some code I can use tho apply a counteracting force? I have tried increasing linear and angular drag and that doesn’t work, Here is my code: I am using visual studio 2019 community.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed;
private Rigidbody2D rb2d;
void Start()
{
rb2d = GetComponent<Rigidbody2D> ();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
rb2d.AddForce(movement * speed);
}
}