Hi,
consider this is what I have:
private void Rotate(Vector3 mouseMoveDelta)
{
Vector3 oldPos = Input.mousePosition + mouseMoveDelta;
Vector3 newPos = Input.mousePosition;
Vector3 oldSwipe = cam.ScreenToWorldPoint(new Vector3(oldPos.x, oldPos.y, 15f));
Vector3 prevSwipe = cam.ScreenToWorldPoint(new Vector3(newPos.x, newPos.y, 15f));
swipeDir = (oldSwipe - prevSwipe) * swipeSensetivity ;
}
This is a usual approach to get world spaced mouse movement delta. So the idea is to do the same thing, but in a proper way - using projection matrix. You can see a lot of problems in the previous snippet: I already have the delta as input, so i don't want to recalculate it but in the world space. I am trying to get rid of Input.mousePosition here.
The value is just a delta, meaning that we don't actually need to consider the camera's location and rotation. Meaning that only projection must be applied. Basically, what should be working - is this:
Vector3 worldSpacedDelta = Camera.main.projectionMatrix.inverse.MultiplyPoint( new Vector3(delta.x, delta.y, 15f) );
But I can't get it right, it's quite hard trying to make sense of random values. Maybe anyone already has the right solution to this?
↧