Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by Monstermash28425R1 · Jan 27, 2019 at 10:14 PM · unity 5monodevelopmonobehaviourvoxel

How to rotate an array of vectors over a normal vector

hi guys! hope that you're fine!

im making a voxel engine, and im looking for a way to do vector rotation i've use Vector3.Reflect() and Vector3.project() over all vectors in array,

to show you how its done i leave a little code below,
however, its no work cuz im storing all block vertex data in that array, so when i run this code them make all vectors project over 4 points, i dont know how to use it, i want to project or rotate all vertex index to do for example, vertex = (0,1,1) --->(1,1,0).

what i want to get is a system like minecraft switch block face pending on player direction

thank you anyway!

the code:

 public class Test : MonoBehaviour
 {
     public Vector3[] verts = new Vector3[]{
         new Vector3 (-0.5f, 0.5f, 0.5f),
         new Vector3 (0.5f, 0.5f, 0.5f),
         new Vector3 (0.5f, 0.5f, -0.5f),
         new Vector3 (-0.5f, 0.5f, -0.5f),
         new Vector3 (0.5f, -0.5f, 0.5f),
         new Vector3 (-0.5f, -0.5f, 0.5f)
         
     };
 
     public Vector3 normal = new Vector3 (0, 1, 0);
     public Vector3[] to = new Vector3[4];
     void Update ()
     {
         if (Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hit)) {
             Debug.Log (hit.normal);
             normal = hit.normal;
         }
         to = new Vector3[verts.Length];
         for (int i = 0; i < verts.Length; i++) {
             to [i] = Vector3.Reflect (verts [i], normal);
         }
     }
     RaycastHit hit;
     void OnDrawGizmos ()
     {
         Gizmos.color = Color.green;
         var last = to [0];
         for (int i = 0; i < to.Length; i++) {
             if (i > 3) {
                 Gizmos.color = Color.blue;
             }
             Gizmos.DrawCube (to [i], Vector3.one * 0.1f);
             if (last != to [i]) {
                 Gizmos.DrawLine (last, to [i]);
                 last = to [i];
             }
         }
     }
 }

Comment
Add comment · Show 1
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 Monstermash28425R1 · Jan 27, 2019 at 07:04 PM 1
Share

beside, i guess i have a more optimized and useful way to do what i want without mesh vertex data modification, i dont try it, but i guess i can set the face uv iterating and casting the RaycastHit.normal with a switch() iteration, i dont know but if it work i leave the solution below, ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Monstermash28425R1 · Jan 29, 2019 at 04:03 PM

figure out my problem
var m = Matrix4x4.TRS(Vector3.zero,Quaternion.LookRotation(normal),Vector3.one);
vector = m.multiplyPoint3x4(vector);
and vector will "rotate" it values

"normal" is the vector were we want to rotate our vector

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

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

monodevelop is not detecting using startapp; 0 Answers

set gamobject via script in non-Monobehaviour class? 1 Answer

Unity3d Dragging object in 3d world 0 Answers

Why won't MonoDevlop open on my Mac using Unity 5? 1 Answer

What books or other study material available for learning destruction physics of 2d terrains like Where's my water and sand balls ? 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