Force from OnMouseEnter/OnMouseExit time?

Hiya.

I’m thinking about a control method where the direction and strength of a force is applied to a gameobject based on the path and speed of the cursor /through/ that object.

To get the force, I’m thinking this can be done simply by using OnMouseEnter, then set a timer running, then at OnMouseExit taking the time and using it as the variable for the force. But what about getting the direction? I guess I’d have to raycast from the camera (static) and work out the hit.point for both the cursor entry point and the cursor exit point over the gameobject, then use this line as the direction relative to camera.

That sound feasible to you guys and gals? I think I can handle the timer bit, but I could use some code help getting the direction!

Rather than use a raycast, you might find it easier to use Camera.ScreenToWorldPoint or Camera.ScreenToViewportPoint to convert the mouse position to a world position in OnMouseEnter/OnMouseExit. Once you have the two points, you can get a direction vector by subtracting the start point from the end point of the drag. The magnitude of that vector is the distance moved and that, divided by the time taken will give you the speed of the drag.