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 Gameart1235 · Oct 25, 2014 at 04:37 PM · mouseparticlemouse follow

Mouse Follow (Not Working) - ):

I want a group of Particle to follow the mouse. but can't get it to work and not sure what I'm doing wrong.

here my code

 #pragma strict
 
 var mouse : Vector3;
 
 function Start () {
 
 }
 
 function Update () 
 {
 
 transform.position = Vector3(Input.mousePosition.x,Input.mousePosition.y,0);
 }

PLZ HELP

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Itaros · Oct 25, 2014 at 04:41 PM

It is absolutely correct if your camera is orthographic and pixel-perfect, otherwise to make it compliant with current camera VP setting use this: http://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html

If there is a need to use that with perspective camera I recommend to set plane(or better - quad) with collider and cast ray to that plane. That way you will have full control on movement plane without the need to mess with projection math and overcomplicating code. The good helper in that is Physics.Raycast: http://docs.unity3d.com/ScriptReference/Physics.Raycast.html

 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 RaycastHit hit;
 if (Physics.Raycast(ray, out hit, 100)){
 transform.position = hit.point;
 }

Take note regarding two things: If y looks reversed in comparison to screen just perform flipping of it by Screen.height. You may need to add mask to make sure in this pass only plane is detected instead of other colliders. Experiment ;)

Comment
Add comment · Show 5 · Share
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 Gameart1235 · Oct 25, 2014 at 06:20 PM 0
Share

Yeah I Did try Camera.ScreenToWorldPoint, but I just can't get it to work with the script I'm not sure how to write it.

Plz Help.

avatar image Itaros · Oct 25, 2014 at 06:32 PM 0
Share

Then describe the problem with more detail if possible. I don't get it.

avatar image Gameart1235 · Oct 25, 2014 at 06:37 PM 0
Share

Ok so I change the script a little

 mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
 transform.position = mouse;

and set the camera to orthographic, and it work Great, but now I need to get it to work with Perspective.

avatar image Itaros · Oct 25, 2014 at 06:44 PM 0
Share

Let me update my answer to accommodate this requirement :)

avatar image Gameart1235 · Oct 25, 2014 at 06:53 PM 0
Share

thank you. Can't wait to try it.

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

28 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mouse follow on network 0 Answers

2D game with 360 degree aiming and shooting a particle system... help please 1 Answer

Reacting to Mouse animation... 2 Answers

swiping with mouse input 0 Answers

Mouse position to Isometric Grid Tile number 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