// Take mouse position
mouse = Input.mousePosition;
castPoint = Camera.main.ScreenPointToRay(mouse);
// Take coordinates for Vector
x=castPoint.direction.x;
y=castPoint.direction.y;
// And make a direction
movement=new Vector2(x,y);
rb.AddForce(movement*speed,ForceMode2D.Force);
But nothing happen
In 2D game*
I think this should do what you are asking for.
First add these variables:
public float RotationSpeed;
private Quaternion lookRotation;
private Vector3 direction;
I think this is what you should use as your script:
public void Update()
{
mouse = Input.mousePosition;
castPoint = Camera.main.ScreenPointToRay(mouse);
//I'm not sure if castPoint has a position in it or not, but if when you type castPoint.transform.position
direction = (castPoint.- transform.position).normalized;
//create the rotation we need to be in to look at the target
lookRotation = Quaternion.LookRotation(direction);
//rotate us over time according to speed until we are in the required rotation
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * RotationSpeed);
}
I used this script for reference, I don’t know what a lot of this actually means (or how Quaternions actually work) but this is my holy grail reference for rotating:
Let me know if that works if if you have other questions.