• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Turret rotation on one axis problems 2 Answers

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

EulerAngles conversion Quaternion problem 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges