- Home /
How to interpret Event.current.delta?
Hello I'm new to Unity. Right now I'm developing my first game and I'd like to know how to interpret Event.current.delta x and y values. When I have object that moves with cursor on screen I track it's last location and new location to be set in current frame process. I can also calculate it's delta position based on those two values but Event.current.delta gives me some absolute value instead of decimal fraction of the movement in World. Now if I recalculate them like this:
Vector3 pos = Camera.main.ScreenToWorldPoint(Event.current.delta);
Then I get values that are closer to what I want but still it's above 1 and it should be at about 0.001. I don't want to recalculate this by myself when Event.current.delta is filled by Unity engine but like the question states: How to interpret Event.current.delta to be usable values? I found out that in camera class there are methods with Matrix4x4 and I think that I should use them to get the same value as the one I get from manual delta calculation but I don't really know how. Of course I may be mistaken so then please correct me.
So basically:
Vector3 pos1 = Camera.main.ScreenToWorldPoint(Event.current.delta);
pos1.z = 0f;
Vector3 pos2 = new Vector3(lastPos.x - newPos.x, lastPos.y - newPos.y, 0f);
pos1 != pos2
How to calculate pos1 to be equal pos2 using Event.current.delta ?
Thanks in advance.
I'd be curious to see how you're getting lastPos and newPos. Event.current.delta is using in conjunction with Event.current.mousePosition. If you calculate last and new based off that current mousePosition, they should match (or at least be close) to the delta.
I just save transform.position to lastPos and newPos is just:
Vector3 newPos = Camera.main.ScreenToWorldPoint(new Vector3(Event.current.mousePosition.x, (Screen.height - Event.current.mousePosition.y) -1, 0f)); newPos.z = 0f;
It's script to control camera based on gameobject movement but only while mouse button is pressed and since I don't want my camera to move across z axis I reset it to 0f.
What's interesting is also the fact that:
Event.current.mousePosition != Input.mousePosition But after above Y axis calculations it is.