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 Jay 2 · Aug 31, 2010 at 05:44 PM · mouseweaponattacklook

How to control a weapon through a single mouse movement?

This is probably more complicated than it sounds, but I'm not sure.

I want to be able to show mouse on screen (easy, I can do this) but then I want it so when the user clicks and drags across the screen, the game remembers this movement for just a moment, and when the movement is finished, it sends an object with the same rotation down the same path the mouse took.

Is this do-able in any way...?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Daniel-Brauer · Aug 31, 2010 at 07:46 PM

This is definitely doable. It just requires that you program it in the same terms that Unity handles that sort of input. Using Update() and Input.GetMouseButtonDown/Up() to act on the beginning and end of the drag. You should compare Input.mousePosition at those two times, and then do whatever you want with the information.

Comment
Add comment · Show 1 · 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 Jay 2 · Aug 31, 2010 at 07:52 PM 0
Share

Thanks very much, it sounds like I'll have to do a lot of research as to how to program the middle part of this, but you've given me a great place to start! Thanks!

avatar image
0

Answer by Techsuport · Sep 04, 2010 at 09:09 PM

for cick, unclick, instantiate, rotate, then move based on obj forward

if(Input.GetButtonDown("Fire1")){//on left mouse click(if deafault settings r used)
    var ray=Camera.main.ScreenPointToRay(Input.mousePosition);//the ray, from can to were u click
    var hit=Raycast;//var the raycast hit info will go in
    if (Physics.Raycast (ray,hit,100)){//raycast
        Debug.DrawLine (ray.origin,hit.point);//shows line
        //save hit.position
    }
}
if(Input.GetButtonUp("Fire1")){//on left mouse click(if deafault settings r used)
    var ray2=Camera.main.ScreenPointToRay(Input.mousePosition);//the ray, from can to were u click
    var hit2=Raycast;//var the raycast hit info will go in
    if (Physics.Raycast (ray2,hit2,100)){//raycast
        Debug.DrawLine (ray2.origin,hit2.point);//shows line
        //~ save hit2.position
        //~ var obj=instanciate obgect
        //~ var dir:Vector3=(hit2-hit.position).normalized;//will give direction from hit to hit2 as a vector3 with magnitude of 1
        //~ var correntForward=obj.transform.TransformDirection(Vector3.forwardl;//local forward Vector3 of obj
        //~ obj.rotation=Quaternion.Lerp(correntForward,dir,1);//rotate instantiated object, not tested btw, dis is sudo code :)
    }//from rotation forward to dir
}

ASK MOAR QUESTIONS, LEANING IS IMPORTANT!!!

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

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

No one has followed this question yet.

Related Questions

weapon bob when looking 2 Answers

How can I let my Sprite look towards the mouse in Unity 4.3 2D? 1 Answer

draw line between mouse and gameobject on flat plane 0 Answers

How can I save MouseLook position in this script ? 0 Answers

Movement with the cursor? 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