I have UI elements that are dragged around, and I want to make them feel a bit more satisfying to move. This is the (functional) script I have to make them follow the mouse position.
public void OnDrag(PointerEventData data) {
Vector3 mousePos = new Vector3(data.position.x, data.position.y, 0);
// Vector3 direction = Vector3.Normalize(mousePos - transform.position);
transform.position = mousePos;
}
What I want to do is to rotate the elements slightly in the direction of movement, so react to the direction and speed with which the player is moving them. The commented line tracks the direction, but I can’t really find a good way to have it rotate according to the direction. I haven’t found a good way to track the speed, either.
Does anyone have suggestions for a solution?