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
-1
Question by DubstepDragon · Mar 30, 2014 at 11:12 AM · positionmouseprojectileclickfire

Firing projectile towards mouse position from player...

I have been trying, research, etc... and I came up with only JavaScript results, which do not suit me since I work with C#. So basically, what I require is, when the left mouse button is clicked, I need a projectile (prefab) to be instantiated from the player's position and to move towards the mouse cursor's position. Now obviously I need it not to follow the cursor, but to fly in a straight line at that position. I cannot yield any results with my incomplete code, so can someone assist me with this problem please?

Comment
Add comment · Show 7
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 guido123 · Apr 01, 2014 at 12:17 PM 0
Share

so you need to convert mouse position to world position, instantiate projectile, then projectile.transform.lookat(mouseposition), and finally just let the projectile move forward with projectile.transform.translate

avatar image senc01a · Apr 01, 2014 at 12:21 PM 0
Share

Should the projectile follow a trajectory parallel to the floor of your world, or should it try to hit the point in the ground that intersects with the user click? Based on this you will want to calculate the transform position and rotation of your projectile before putting it to advance.

avatar image DubstepDragon · Apr 09, 2014 at 10:34 AM 0
Share

I've slightly changed how I want it to be - what I now want is the player character to be rotated to always face the mouse cursor, whereas the projectile has no involvement whatsoever. How can I rotate the player to always face the mouse cursor?

It's a top-down game, if it helps.

avatar image wijesijp · Apr 09, 2014 at 10:48 AM 0
Share

following will cause the player to always look at mouse position

 void Update () {
         transform.LookAt(mouse position );
     }
avatar image robertbu · Apr 10, 2014 at 04:15 PM 0
Share
  • 2D or 3D?

  • What is the orientation of your top down? That is, is the camera looking down the 'y' axis or did you construct your game so that the camera looks towards positive 'z'?

  • How is your model constructed? That is, is the 'forward' of the object facing positive 'z' when the rotation is (0,0,0)?

  • Orthographic or perspective camera?

  • If 3D with a perspective camera, at what distance from the camera do you want to define the mouse cursor?

  • Is the camera parallel to the plane of rotation or at an angle?

Show more comments

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

24 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

Related Questions

Fire missile to mouse click 1 Answer

Fire object towards mouse cursor 1 Answer

Firing towards mouse- aim in all directions? 1 Answer

Spawn Objects Where i click 2 Answers

click on screen to get the coordinate on the ground(x,z plane) 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