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 sparkzbarca · Jun 30, 2013 at 09:00 PM · mathangle

is this the right way to find an angle?

trying to take a weapon turret and a target and rotate the weapon to aim at the target.

I'm not just rotating though because the weapon has a horizontal and vertical dial so i want to really do 2 rotations at once and I think that means i basically need to find 2 angles, the x angle and the y angle and rotate seperatly each dial on the right axis the right amount. I'm also working within angle constraints so weapons don't have 360 views.

because i'm doing 2 rotations instead of 1 it seems like i should be doing 2 2d rotations so i'm using vector2 not vector3.

for the x rotation i'm ignoring the y axis and for the y im ignoring the x.

 vector2 XWeapon;
 vector2 XTarget;
 vector2 YWeapon;
 vector2 YTarget;
 
 
             XWeapon.x = WeaponTransform.position.x;
             XWeapon.y = WeaponTransform.position.z;
             
             YWeapon.x = WeaponTransform.position.y;
             YWeapon.y = WeaponTransform.position.z;
             
             XTarget.x = AimPoint.x;
             XTarget.y = AimPoint.z;
             
             YTarget.x = AimPoint.y;
             YTarget.y = AimPoint.z;
             
             XAngleToTarget = Vector2.Angle(XWeapon,XTarget);
             YAngleToTarget = Vector2.Angle(YWeapon,YTarget);


I'm just wanting someone to confirm to me that that looks like the right way to do it (so it'll work, i'll be testing of course but i want to make sure in principle it should work) and that i'm not going the long way about doing it.

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
0
Best Answer

Answer by robertbu · Jun 30, 2013 at 10:17 PM

I don't see how you use the two ?AngleToTarget values, but one issue is that Vector2.Angle() is unsigned, so you are not going to know which direction to rotate to aim your weapon. Another potential issue is that you are not calculating vectors from the right locations. You are using a vectors from the world origin, not vectors from the weapon in calculating the angles.

I posted a turret solution here:

http://answers.unity3d.com/questions/388185/make-the-turret-automatically-rotate-to-look-at-wh.html

There is no rotation limit, but it does handle the separate up/down, left/right rotations.

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

15 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

Related Questions

Problem with Clamping Values for Object's Rotation 1 Answer

[CG vertex shader] Surface normal to screen angle 1 Answer

Calculate mid angle position based on three points 1 Answer

Simple angles question - How to get the position to the right of an object relative to their current direction? 1 Answer

Finding the angle to bounce object to target 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