Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 vestax_ion · Aug 22, 2011 at 09:33 AM · quaternionrotateprojectilespawnpoint

Rotate Spawnpoint running into errors

I dont know why coding this is so difficult! i feel dumb!

I want to rotate the spawnpoint inside a loop so that it instantiates 10 gamobjects in different directions. Am i mixing up quaternions and eulerangles? (i tried so many versions of the "spawnpoint.transform.Rotate" that by now it probably has a $yntax error.

 var gridX = 1; 
 var gridY = 8; 
 var spacing = 1.0; 
 var blocks : GameObject[];
 private var rot : Quaternion;
 var sp : GameObject;
 
 sp = GameObject.Find("spawnpoint");

 function Start () { 
 for (var y = 0; y < gridY; y++) { 
 
 sp.transform.RotateAround(Vector3.up,20*y);
  for (var x = 0; x < gridX; x++) { 
 

 
 rot.eulerAngles = Vector3(0,0,0);//you can rotate this at 45 etc and also mult byx
  var ino = Instantiate(blocks[Random.Range(0, blocks.Length)], Vector3 (x-4, 6, 4) * spacing, rot);
  ino.transform.localScale += Vector3((Mathf.Pow(Random.Range(0,1.7), 4)),(Mathf.Pow(Random.Range(0,1.6), 5)),(Mathf.Pow(Random.Range(0,1.7), 4)));
  

   }
  } 
 } 

EDIT= Apparent Answer:

the instantiation command doesnt seem to have any relation to the spawnpoint position and rotation unless you manually calculate the new global positions and rotations as functions of the spawnpoint rotation and position. ??? i thought that if you just rotate a spawnpoint you can have objects instantiate in positions relative to it, but no!!!

you have to do something like this:..? http://answers.unity3d.com/questions/41726/instantiating-in-a-position-relative-to-an-object.html

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

Answer by roamcel · Aug 22, 2011 at 12:36 PM

I hope I'm not underestimating your problem, but I think that you just need

 spawnpoint.transform.RotateAround(Vector3.up,myangle);

and be absolutely sure that

 objRot = spawnpoint.transform.rotation;

since as of now you're setting all of ino's rotations to 0 eulers.

Comment
Add comment · Show 4 · 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 vestax_ion · Aug 24, 2011 at 09:06 AM 0
Share

thanks! i wishing to rotate instantiated objects about themselves and also to rotate the spawnpoint so that i can project instantiated objects into patterns with a central symmetry.

so i did the script from zero again, and if i write, as you suggest:


var sp : GameObject;

sp = GameObject.Find("spawnpoint");

function Start () { for (var y = 0; y < gridY; y++) {

sp.transform.RotateAround(Vector3.up,20*y);

.......


i have this error: NullReferenceException: Object reference not set to an instance of an object UnityEditor.ListViewShared.Has$$anonymous$$ouseDown (UnityEditor.InternalListViewState ilvState, Rect r, Int32 button) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/$$anonymous$$ono/GUI/ListViewShared.cs:180) UnityEditor.ListViewShared.Has$$anonymous$$ouseDown (UnityEditor.InternalListViewState ilvState, Rect r) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/$$anonymous$$ono/GUI/ListViewShared.cs:175) UnityEditor.ListViewShared+ListViewElementsEnumerator.$$anonymous$$oveNext () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/$$anonymous$$ono/GUI/ListViewShared.cs:368) UnityEditor.ConsoleWindow.OnGUI () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Editor/$$anonymous$$ono/ConsoleWindow.cs:422) System.Reflection.$$anonymous$$ono$$anonymous$$ethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)

It seems to be a referenced script in a unity system file, maybe because i reinstalled 3.3 after uninstalling 3.4?

avatar image roamcel · Aug 24, 2011 at 09:49 AM 0
Share

Well the downgrade thing might not be of help, however:

assure that

sp = GameObject.Find("spawnpoint");

is not returning null, before sp.transform

besides, I don't remember if you can call RotateAround as a procedure. In C# you need to declare a new transform, copy sp.transform into it, rota$$anonymous$$round the new transform and finally assign sp.transform = newtransform.

avatar image vestax_ion · Aug 24, 2011 at 11:58 AM 0
Share

Thanks! I found that my main problem was that the instantiation transform.position was not set to the spawnpoint position, omly a globalscale thing, so i obviously have to set the rotation to spawnpoint.transform.rotation+instantiated object rotation, the script was just in the gameobject's attributes but i forgot to assign it!

also there is a bug in some scripts causing an error when i add the line, something to do with keyboard rotate. maybe due to converting a project to 3.4 and back to 3.3, because now my keyboard orbit script is just making things fall in y direction very fast, even though the script is the same. Thanks!!!

avatar image roamcel · Aug 24, 2011 at 02:47 PM 0
Share

Glad you sorted it out :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Find trajectory angle needed to hit an object 0 Answers

Rotation of an object 3 Answers

Quaternions- how to leave out Y rotations... 1 Answer

Rotation not working 3 Answers

Inheritance code acts differently (Quaternion.LookRotation) 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