Question by
myC4 · Jul 19, 2020 at 08:39 AM ·
rigidbody2drigidbody.velocity
rigidbody2d velocity in direction x / y
Hey,
I want to move a rigidbody2d in the direction of the mouse. Here is my code:
public class Move : MonoBehaviour
{
public float speed;
public Vector3 mousePos;
public Rigidbody2D rb2d;
void Start()
{
rb2d = gameObject.GetComponent<Rigidbody2D>();
mousePos = Input.mousePosition;
rb2d.velocity = new Vector2(mousePos.x, mousePos.y);
}
}
but this will move it at a speed depending on where in the world it is. I want to move it in the direction of the cursor but always at the same speed. The player is always in the middle of the screen (camera), if that helps
Comment
Your answer