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 ZeraTFK · Sep 13, 2014 at 07:58 PM · movementinstantiatemeshrotatedirection

Problem with the look direction after Instanciate/Rotate

Hi at all helper,

i have a big problem in rotate a GameObject.

The orginal gameobject is a Spider and it's position is 0,0,0 (world center). All the directions are correct:

alt text

Blue is the forward direction.

Now i instantiate the Spider and place it anywhere on a large Sphere with

 ...
 
 if(Random.Range(1,3) == 1){
                 this.spawned_mob_list.Add((GameObject)Instantiate( Orginal_Spider));
             }else{
                 this.spawned_mob_list.Add((GameObject)Instantiate( Original_Mobo));
             }
 
             this.GetNewMobPosition(this.spawned_mob_list[this.spawned_mob_list.Count-1].transform);
 
 
 
 
 ...
 
 private Vector3 GetNewMobPosition(Transform t){
         float angle = Random.Range(0,360);
         //float dist  = Random.Range(10,30);
         float dist  = Random.Range(2,3);
 
         t.position = player.position;
         //t.rotation = player.rotation;
         t.RotateAround(t.position, t.up, angle);
         t.position = t.position + t.forward.normalized * dist;
 
         RaycastHit hit = new RaycastHit();
         Vector3 tmp = (new Vector3(0,0,0) - t.position).normalized;
         Vector3 dtmp = (new Vector3(0,0,0) + t.position);
 
         if(Physics.Raycast(transform.position + dtmp, tmp, out hit)){
             t.position = hit.point;
             t.rotation =  Quaternion.FromToRotation(t.up, hit.normal);
 
         }
 
         return t.position;
     }

And i have a function for gravity on a Update() Function:

 protected void DoGravity(){
         if (this.gravitytype == GravityType.NORMAL){
             Vector3 gVector = (new Vector3(0.001f,0.001f,0.001f) - transform.position).normalized;
             transform.rotation = Quaternion.LookRotation(transform.forward, -gVector);
             rigidbody.AddForce(gravity * gVector);
         }
         else{
             int iDefLAyer = gameObject.layer;
             gameObject.layer = 2;
             RaycastHit hit = new RaycastHit();
             Vector3 tmp = (new Vector3(0,0,0) - transform.position).normalized;
             Vector3 dtmp = (new Vector3(0,0,0) + transform.position).normalized;
 
             if(Physics.Raycast(transform.position + dtmp * 0.5f, tmp, out hit)){
                 transform.position = hit.point;
                 transform.rotation = Quaternion.LookRotation(transform.forward, hit.normal);
 
             }else if(Physics.Raycast(transform.position + dtmp * 100, tmp, out hit)){
                 transform.position = hit.point;
                 transform.rotation = Quaternion.LookRotation(transform.forward, hit.normal);
                 
             }
             gameObject.layer = iDefLAyer;
         }
     }


The rotation is already like the original GameObject and has no own rotation alt text

How can i rotate the Spider correct to the hit.normal of the Raycast with it's own rotation?

prob2.jpg (184.0 kB)
prob1.jpg (207.2 kB)
Comment
Add comment · Show 3
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 Fanttum · Sep 13, 2014 at 08:22 PM 0
Share

Hmmm, not really sure what all is going on here, but I am wondering if your global and local directions got mixed up?

Transform

Transform.localPosition

Transform.localRotation

avatar image ZeraTFK · Sep 13, 2014 at 09:13 PM 0
Share

I compared the rotation of the real gameobject with the clone gameobject and the clone has always the direction of the real one.

How can i rotate the clone GameObject on the Sphere with its own direction... Why keep the Clone the Original direction?

avatar image ZeraTFK · Sep 13, 2014 at 09:54 PM 0
Share

Whats wrong?

if i rotate my Clone with

 transform.parent.transform.Rotate(0f, doTurn, 0f);

It will rotate the GameObject with the mesh.. The rotation int the Inspector of the clone is chanced to. But the rotation with the rotate button in the scene doesnt chance... It work if i rotate it manually in scene...

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Updating new cube face positions after rotation 0 Answers

why does Infinite Runner Terrain Collider break my game? 0 Answers

Instantiate object at position, moving in a direction? 1 Answer

How can I move an object to click point in 2D? 0 Answers

Instantiated object not rotating around the center 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