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 Brontupisto · May 15, 2014 at 05:12 AM · rotationinstantiateraycastinstantiation

Setting rotation parallel to ground

I'm making a game where you graffiti on walls. My current code aligns the instantiated decal to the normal of the object being sprayed on, however often it appears upside-down or sideways, so I want to make it align to the ground so it is facing 'up'. I also want to add functionality to rotate the graffiti around the normal by moving the mouse left and right, but my priority is making it appear the right way up.

 function Spray()
 {
      var hit: RaycastHit;
      if (Physics.Raycast(transform.position, transform.forward, hit))
      Debug.DrawLine(transform.position,hit.point,Color.red,1.0f);
      {
          if (hit.transform.tag == "Surface")
          {
              var rot = Quaternion.FromToRotation(Vector3.up, hit.normal);
              gernz = Instantiate(tagged,hit.point+(hit.normal*0.0001),rot);
              Debug.Log("hehe");
          }
      }
 }

alt text

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 · May 15, 2014 at 05:32 AM

Shocked. Graffiti on walls? Next thing you know they'll be writing a game about stealing cars! ;)

Untested, but if you are writing on walls (or mostly vertical surfaces) you can do:

  • Use a Quad (or a Sprite) for the graffiti texture.

  • Replace line 9 with the following line of code:


    var rot = Quaternion.LookRotation(-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 Brontupisto · May 15, 2014 at 05:42 AM 0
Share

Not only on walls, but on trains too. Also, you sell meth to get money for paint cans :)

Thanks, that seems to be on the way to what I'm after. I'm not familiar with Quads and Sprites, so I'm not sure if what is happening now is a result of using a plane prefab with the decal texture on it.

alt text

avatar image robertbu · May 15, 2014 at 05:48 AM 0
Share

A Quad is a two-triangle, vertical plane. You create one by:

 GameObject > Create Other > Quad

So you want your game object that use use for your graffiti textures to be Quads, not Planes.

The code I posted won't work with a plane. If you really want a plane for some reason, you can use an empty game object as a parent and rotate the visible child object so that the graffiti is vertical when the empty parent's rotation is (0,0,0).

Note that I ran a quick test of the Quaternion.LookRotation(), and it worked. The reason it works is there is an optional second parameter that defines 'up' for the LookRotation(). By default it is Vector3.up.

avatar image Brontupisto · May 15, 2014 at 06:17 AM 0
Share

Awesome, it seems to have worked. Thanks heaps.

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

20 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

Related Questions

Instantiate not shooting in right direction 1 Answer

transform position and rotation of instantiated object 1 Answer

Making a particle effect parallel to the slope of a terrain 1 Answer

A way to instantiate an item with 90 Degree increments? 2 Answers

Make an instantiated object match the slope of the terrain 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