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 Harald921 · May 10, 2015 at 06:49 PM · rotationgameobjectvector3quaternioneulerangles

How do I make create a rotateable object that follows a raycast hit point?

So I have created a script detecting the point where the raycast hits, and I have been able to instantiate a prefab to that point, but all I wish to do is to be able to rotate this on both the X and the Y axis, as the object that is going to repeadetly spawn/despawn is rotated 90 degrees on the wrong axis. And I also want to be able to rotate it on the Y axis so that I can later on place it.

Any ideas how I can change the rotation of the Quartenion?

Small gif of how it works right now: http://recordit.co/JPxHUsOk5A

Code used:

 var rotation = Quaternion.identity;
 Instantiate(bScript.shelterPrefabMarker, hit.point, rotation);
     



in the update function.

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

2 Replies

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

Answer by Harald921 · Jul 22, 2015 at 02:20 PM

If anyone else stumbles upon this, this is how I solved it (C#):

 tmp.transform.position = hit.point;
 
 if (Input.GetKey(KeyCode.Q))
      tmp.transform.Rotate(0, -rotationSpeed * Time.deltaTime, 0);
 
 else if (Input.GetKey(KeyCode.E))
      tmp.transform.Rotate(0, rotationSpeed * Time.deltaTime, 0);
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
avatar image
1

Answer by fighder · May 10, 2015 at 08:09 PM

I wouldn't suggest changing the Quaternion, cuz messing around with Quaternion is just not a good idea unless you understand it.

What you can do is the following:

 var temp : GameObject = Instantiate(bScript.shelterPrefabMarker, hit.point, Quaternion.identity) as GameObject;
 
 temp.transform.rotate(90,90,90); //rotate your gameObject

I am not too familiar with javascript syntax, but basically you grab the gameObject that will be spawned with type casting, and then rotate the object.

Comment
Add comment · Show 1 · 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 Harald921 · May 11, 2015 at 04:36 AM 0
Share

Okay, thanks, I will try it out later when I get home. The reason I need it rotated is because, I use it as a object detecting collision with different building materials, and when all the variables have reached a certain value, the building is instantiated.. 90 degrees in the wrong x rotation. But many thanks!!

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

Instantiate GameObject towards player 0 Answers

How is the rotation of a Transform converted into a Vector3 in the inspector ? 2 Answers

c# modify only one axis of a quaternion 2 Answers

Turret rotation on one axis problems 2 Answers

Rotating a GameObject based on another GameObject's y-axis 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