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 /
This question was closed Apr 08, 2014 at 10:21 PM by Benproductions1 for the following reason:

Duplicate Question

avatar image
0
Question by Gimil · Apr 07, 2014 at 06:06 PM · c#angleunitmouse click

How to get angle from unit to mouse click?

Hi, I can't figure out how to get an angle between unit and mouse click. I need it in C#. Angle from charactercontroller which is casting the spell to point where i clicked while ago by mouse. alt text

Can you get it now? :P I cast a spell (C# trigger) and i want to get this angle.

simple thing.png (20.1 kB)
Comment
Add comment · Show 3
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 Benproductions1 · Apr 08, 2014 at 12:19 PM 0
Share

Please be more specific as to what "unit" is and what sort of an angle you need.

avatar image senad · Apr 08, 2014 at 03:09 PM 0
Share

It would be best for you to draw a diagram. :)

avatar image perchik · Apr 08, 2014 at 05:02 PM 0
Share

What have you tried? Do you have any logic that you've come up with?

Questions of the form "I need this script--do it for me" usually don't get a lot of help

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Joyner · Apr 08, 2014 at 05:37 PM

i guess it's the same question

http://answers.unity3d.com/questions/340102/trouble-calculating-angle-between-an-object-and-mo.html

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 Gimil · Apr 08, 2014 at 09:09 PM 0
Share

Oh, its what i were looking for X_x, thanks idk how couldnt i find it.

avatar image
0

Answer by djfatsteve2 · Apr 08, 2014 at 05:37 PM

Is THIS what you're lookin' for? :) I typed it up in Windows Sticky Notes so I'm absolutely unsure as to if this works. It's along the lines of what you're trying to do though.

 #pragma strict
 var projectile:GameObject;
 var projectileSpeed:float=10;
 
 if (Input.GetMouseButtonDown(0)){
   var touchPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
   var shootDir = new Vector3(transform.position.x - touchPosition.x,  transform.position.y - touchPosition.y , transform.position.z - touchPosition.z);
   shootDir.Normalize();
   strike(shootDir);
 }
 
 function strike(shootDir : Vector3){
   var rotation1 = Quaternion.LookRotation(shootDir);
   var projectile = Instantiate(projectilePrefab, Vector3(transform.position.x,transform.position.y,transform.position.z), rotation1);
   projectile.rigidbody.velocity = projectile.transform.up*-projectileSpeed;
 }



Well... Nevermind.... You want it in C# =/

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 Benproductions1 · Apr 08, 2014 at 10:27 PM 0
Share

Just a note,

 new Vector3(v.x - u.x, v.y - u.y, v.z - u.z)

Is exactly the same as:

 v - u

And

 f(new Vector3(v.x, v.y, v.z))

Is exactly the same as:

 f(v)

You should also type your variables, as it not only makes your code more efficient, it also reveals bugs ;)

Follow this Question

Answers Answers and Comments

26 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Flip an object by 180° (C#) 0 Answers

how to get a correct rotation 2 Answers

Rotate a particle emmiter 0 Answers


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