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 Teiwaz · Jul 08, 2013 at 12:23 PM · rotationprefabs

Set the orientation of a Prefab

So i have some Prefabs which will be my Level Parts. How to Spawn them in rotated ? I am also spawning the same Prefab multiple times. So i want it one time in one direction one other time in another:

Here is a Example:

alt text

Thanks for you help.

Greetings

Teiwaz

prefabsorientation.png (123.8 kB)
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 Benproductions1 · Jul 08, 2013 at 12:27 PM 1
Share

$$anonymous$$ore information is required to give an answer

2 Replies

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

Answer by amphoterik · Jul 08, 2013 at 12:30 PM

The instantiate method allows you to specify a position as well as a rotation. Therefore, if you new the rotation and position you wanted, you could write:

 Instantiate(prefab, position, rotation);

This allows you to make multiple objects each with their own rotation. More info can be found here: http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html

Comment
Add comment · Show 7 · 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 Teiwaz · Jul 08, 2013 at 01:24 PM 0
Share

Exactly this i tried. And it didnt work. Dont know why.

avatar image amphoterik · Jul 08, 2013 at 01:27 PM 0
Share

Can you show me the code?

avatar image Owen-Reynolds · Jul 08, 2013 at 04:03 PM 0
Share

An easy way to make a rotation is: 0 degrees is Quaternion.identity (this is listed in the Instantiate docs.) 90 degrees is Quaternion.Euler(0,90,0); and so on.

They go where "rotation" is.

Or, if you hate long lines, before Instantiate put: `Quaternion rotation = Quaternion.Euler(0,180,0);

avatar image Teiwaz · Jul 08, 2013 at 04:32 PM 0
Share

Current no access to the code. Will post the chunk later.

Greetings

Teiwaz

avatar image Teiwaz · Jul 08, 2013 at 07:10 PM 0
Share

That way i set the rotation of a part.

 public void RotateLevel(Comp$$anonymous$$atrix.direction rotation){
         switch(rotation) {
             case Comp$$anonymous$$atrix.direction.LEFT:
                 transform.rotation= Quaternion.Euler(new Vector3(0,90,0));
                 my$$anonymous$$atrix.RotateComp$$anonymous$$atrix(Comp$$anonymous$$atrix.direction.LEFT);
                 //Debug.Log("Rotate Left");
             break;
             
             case Comp$$anonymous$$atrix.direction.RIGHT:
                 transform.rotation= Quaternion.Euler(new Vector3(0,-90,0));
                 my$$anonymous$$atrix.RotateComp$$anonymous$$atrix(Comp$$anonymous$$atrix.direction.RIGHT);
                 //Debug.Log("Rotate Right");
             break;
             
             case Comp$$anonymous$$atrix.direction.TURN:
                 transform.rotation= Quaternion.Euler(new Vector3(0,180,0));
                 my$$anonymous$$atrix.RotateComp$$anonymous$$atrix(Comp$$anonymous$$atrix.direction.LEFT);
                 my$$anonymous$$atrix.RotateComp$$anonymous$$atrix(Comp$$anonymous$$atrix.direction.LEFT);
                 //Debug.Log("Rotate 180°");
             break;
         
             default:
                 Debug.Log("Unknow Direction");
             break;
         }
     }

and then i simply instatiate it that way:

 theLevel[x,z] = Instantiate(theLevel[x,z],new Vector3(x * theLevel[x,z].transform.renderer.bounds.size.x, 0, z * theLevel[x,z].transform.renderer.bounds.size.z), theLevel[x,z].transform.rotation) as GameObject;

Greetings

Teiwaz

Show more comments
avatar image
-1

Answer by sparkzbarca · Jul 08, 2013 at 12:31 PM

instantiate(prefab,position,rotation)

change rotation to change its rotation.

you can just do a normal rotation plus or minus 90/180 degrees to do a simple rotation

Comment
Add comment · Show 6 · 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 Teiwaz · Jul 09, 2013 at 10:12 AM 0
Share

But how to save the Rotation of a prefab before ?

Iam scanning my level and setting the rotation for each GameObject with:

 transform.rotation= Quaternion.Euler(new Vector3(0,90,0));

And later simply instatiate it like you said before. But this didnt work. He everytime use the same Rotation.

avatar image Benproductions1 · Jul 09, 2013 at 10:15 AM 0
Share

@Teiwaz What you said was literally: "I'm setting the rotation of all my objects to be the same, but it's not working... they are all the same." ???

dat logic

avatar image sparkzbarca · Jul 09, 2013 at 12:45 PM 0
Share

based on the code i can see what your trying to do.

You want to rotate the level but like be able to press a left twice for example and rotate 180 degrees.

the easiest way to rotate is

 if(RotateLeft)
 Angle = 90;
 
 else if(RotateRight)
 angle = -90;
 
 else if (UTurn)
 angle = 180;
 
 
 transform.rotation.rotate(new vector3(0,angle,0));

avatar image Teiwaz · Jul 10, 2013 at 07:36 AM 0
Share

Not realy what i want to do but basicly you hit the point. i created a level generator. You can define a maxSize ( 100x100 Chunks). Also you define a filling%. The level is filled with empty Chunks. Then i set the filled Chunk as like a Ball trown in a 2- Dimensional Array. This Ball bounces random within the Array Fileds, and slow the Level (the white fields are beeing applyed where the level is filled).

In the second funktion i check a compatibility $$anonymous$$atrix of each filled part agains different prefabs. If the are equal i set the prefab at the current position. To ensure that the Part fit / didnt fit, i need to ROTATE the prefab. Cause like on the Screenshot you can see the bottom and the top one are the same just rotated. So normaly i just need to set the rotation of the Prefab.

This ONLY works if i do this direct at the time i SCAN the parts. If i try to scan the level first and after that in a second funktion instatiate the Prefab with nearly the SA$$anonymous$$E code has a different effekt ! alt text

 theLevel[x,z] = Instantiate(go,new Vector3(x * go.transform.renderer.bounds.size.x, 0, z * go.transform.renderer.bounds.size.z),Quaternion.AngleAxis(go.GetComponent<LVL_Patch>().myRotation - 180,Vector3.up)) as GameObject;

<- That way it works. But i want the code to be more modular. So i want first scan, safe the right prefab and instatiate it with the right rotation in a second funktion. And this doesnt work.

lvgen.png (61.5 kB)
avatar image Benproductions1 · Jul 10, 2013 at 11:21 PM 0
Share

So you have a method that works, you just want to split it up, and that doesn't work? How about telling us more about "this doesn't work", rather than complaining about it

Show more comments

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

19 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

[HELP] Rotate Bullet Script 0 Answers

keeping the player upright 1 Answer

How to make Main Camera shake correctly when getting attacked? 1 Answer

Help regarding World-Local Transfrom Rotation? 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