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 HavocInferno · Nov 20, 2014 at 04:22 PM · rotationraycastquaternionparticle systemraycasthit

How to get Raycast surface normal to align particle system?

Hi there.

Setup is this: I have a particle system, that displays correctly when set to Euler rot (270,0,0).

Now what I want to do is raycast through my camera center and instantiate the particle system where the ray hits, however the particle system needs to be aligned with the surface it's instantiated on.

By aligned, I mean it's "upward" axis should be parallel to the surface's normal.

My code currently only spawns it facing "upward" in world space, mostly because I dont know how to rotate it the way I want it to be:

 if(Input.GetButtonDown("Fire1"))
         {    
             RaycastHit hit = new RaycastHit();
             if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 50.0f))
             {
                 Instantiate (boom, hit.point, Quaternion.Euler (270,0,0));
             }
         }


(It's supposed to be an explosion into one direction, so it needs to explode/face away from the point of detonation)

Comment
Add comment · Show 2
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 robertbu · Nov 20, 2014 at 04:27 PM 0
Share

What direction in world space is your particle system facing if you use Euler(270,0,0)? Or another way to ask the same question. Or another way to get at the same information, what direction would be normal be facing if Euler(270,0,0) was the correct solution?

avatar image HavocInferno · Nov 20, 2014 at 09:29 PM 0
Share

Euler(270,0,0) has the particle system facing in World +Y direction.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by 2dkot · Nov 20, 2014 at 04:51 PM

Try to check RaycastHit.normal

I did not try but it could something like this

 Instantiate (boom, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
Comment
Add comment · Show 3 · 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 HavocInferno · Nov 20, 2014 at 09:29 PM 0
Share

I thought about that, but after googling around it seemed like the hit.normal would basically be the reflection vector of the hitting ray.

ED: Hold on, I did try that. However, then the particle systems were still rotated 270/-90° on the x rot axis. Also, still not sure whether hit.normal actually returns the reflected ray, or the actual surface normal of the hit spot.

avatar image robertbu · Nov 20, 2014 at 10:13 PM 2
Share

@2dkot is close. Given the way you've described it, you should do:

   Instantiate (boom, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal));

Alternately you could create a combined rotation:

    var q = Quaternion.FromToRotation(Vector3.up, hit.normal) * Quaternion.Euler(270,0,0);
    Instantiate (boom, hit.point, q);
avatar image HavocInferno · Nov 21, 2014 at 07:53 AM 0
Share

Yes! Vector3.forward did the trick (as woud likewise the second combination).

Thanks a lot guys!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Quarternion.LookRotation is only rotating my game object on one axis 1 Answer

Rotating to Slope 1 Answer

Raycasting and changing player rotation accoording to what is underneath. 0 Answers

Rotate Player to Match Surface Normal While Still Maintaining Y Rotation 0 Answers

Object slope rotation issue 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