Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by t0meck · Nov 12, 2012 at 09:52 PM · positioneventscreentoworldpointdelta

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Yokimato · Nov 12, 2012 at 10:02 PM 0
Share

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.

avatar image t0meck · Nov 12, 2012 at 10:10 PM 0
Share

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.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to keep the same position of the object instead of camera 0 Answers

Player position with script and screen sizes 0 Answers

ScreenToWorldCoordinates not accurate 1 Answer

Check if navmesh is at mouse position 0 Answers

How can I change touch location to map location? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges