Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 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 MrJamieMcC · Apr 07 at 05:16 PM · vector3lookatvectorvector2aim

[HELP] Translating vector 2 co-ordinates to real space

I think the title is correct. Tbh i'm not too sure what i need be implementing hence the post.


I am wanting to create a weapon fire pattern using Bitmap images such as this HERE. In which the recoil of the gun will follow the pattern specified. Green is where the first shot will be (the center of the crosshair), then it follows the blue and finally ends on red.I then generate a list of Vector2 which based on the co-ordinates of the pixels in the given image. The output result looks like... X16:Y0, X16:Y1, X15:Y2... and so on.... this part of the code works correctly.


The trouble i am having is getting the crosshair (center of camera) to actually look at the Vector2 co-ordinates.

The following code i am using is:

 void LookAtTarget()
     {
         Vector3 currentView = Camera.main.transform.forward;
         Vector3 addView = new Vector3(generateScript.GetVector(point).x, generateScript.GetVector(point).y, 0);
         Vector3 newView = currentView + addView;
 
         transform.LookAt(newView);
        
         point++;
 
         Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward * 100, Color.yellow, 100f);
     }

When the gun is fired the above method is called. The theory i had was to simply get what the camera is currently looking at and add the new Vector2. However the results are not what i desired. You can see a GIF of the results HERE. The "point" variable is used to indicate which vector to aim at next from the list


I THINK the issue is related to the 2D/3D conversion, as you can see from the GIF the weapon does not take into consideration the current view (in this example it was straight forward) and instead aims at the 2D vector on the screen space and not world space.

Could anybody offer some guidance or support please? Thank you kindly

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

Answer by jackmw94 · Apr 08 at 12:06 AM

I think your first problem might be that you’re conflating a look direction with a look target. You pass the look at function the latter whereas you’re using the former. For example if your transform is at (0,0,-2) and you call look at passing (0,0,-1) it will look forward at it’s looking at the position 1 unit in front of it.

It looks as though you want to set its forward direction, you can do this by setting its rotation using Quaternion.LookRotation (https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html)

 transform.rotation = Quaternion.LookRotation(newView, Vector3.up);


Let me know how you get on with this :)

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

168 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 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 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 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 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 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

Clamping LookRotation. 1 Answer

Why the object being moved is faster than the rest? 1 Answer

Get mapping postion of 1 point on a plane defined by 3 points 1 Answer

Make an FPS gun point at the mouse position. 2 Answers

Calculate UV-coordinates based on known vertices and their respective UVs 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