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 bgnoatto · Jul 15, 2011 at 03:11 PM · anglespaceshipdegreesturn

turn 180 spaceship

Hello UA

Excuse my English, I tell them what my problem.

I'm programming the physics for a spacecraft, I've managed to turn like an airplane, when you move to the sides, and am now developing the 180 degree turn.

I succeeded, but my problem is that this rotation depends on the time so I have developed.

He commented that the turn has first to turn on the X axis to show the bottom of the spacecraft, and then rotate in the Z axis to return to the right side.

This shift should be discontinued at any time and start again, in the sense that is given to ASWD.

I would not be so, as you should be able to change the sense of direction at the moment is making the turn. I spent a bit of code, clarified that the move to the sense in watching the ship, already developed elsewhere.

 turnSpeed = 7.0f;
 tiltSpeed = 3.0f;
 tiltAngle = 40.0f;
 angle = 0.0f;
 dir = 1.0f;

 terminoGiro = true;
     
 parte1 = false;
 parte2 = false;
 
 duracionGiro = new LinearInterpolator(0,1,1);

 void Girando()
 {
     horizontalDirectionTurn = Input.GetAxis("Horizontal");
     verticalDirectionTurn = Input.GetAxis("Vertical");
 
     dTime = Time.deltaTime;
     
     desiredDirection = new Vector3(horizontalDirectionTurn, 0, verticalDirectionTurn).normalized;
     
     if (terminoGiro)
     {

        if (!desiredDirection.Equals(Vector3.zero))
         {
             if ((Vector3.Angle(desiredDirection,transform.forward) > 2) && 
                      (Vector3.Angle(desiredDirection,transform.forward) < 100)) { 
                 
                 if (Vector3.Cross(desiredDirection, currentDirection).y > 0.0f)
                 {
                     dir = 1.0f;
                 }
                 else
                 {
                     dir = -1.0f;
                 }
                 angle += tiltSpeed * dTime;
                 currentDirection = 
                 Vector3.Slerp(currentDirection, desiredDirection, turnSpeed * dTime);
                 
                 angle = Mathf.Clamp(angle, 0.0f, 1.0f);
                 transform.LookAt(transform.position + currentDirection);
              
                 body.localEulerAngles = new Vector3(0,0, tiltAngle * angle * dir);
             } 
             else if (Vector3.Angle(desiredDirection,transform.forward) > 100) 
             {
                 terminoGiro = false;
                 parte1 = true;
             }
             else
             {
                 angle -= tiltSpeed * dTime;
                 angle = Mathf.Clamp(angle, 0.0f, 1.0f);
                 transform.LookAt(transform.position + currentDirection);
              
                 body.localEulerAngles = new Vector3(0,0, tiltAngle * angle * dir);
             }    
         }
         else
         {
             angle = 0;
             angle = Mathf.Clamp(angle, 0.0f, 1.0f);
             transform.LookAt(transform.position + currentDirection);
              
             body.localEulerAngles = new Vector3(0,0, tiltAngle * angle * dir);
         }
     }
     else
     {
         if(parte1)
         {
             currentDirection = 
             Vector3.Slerp(currentDirection, desiredDirection, turnSpeed * dTime);

             transform.Rotate(-180 * dTime,0,0,Space.Self);
             
             duracionGiro.Interpolate(); //timer 1s
             
             if (duracionGiro.HasFinished()) //timer finish?
             {
                 duracionGiro.Reset();
                 parte2 = true;
                 parte1 = false;
             }
             
         }
         if (parte2)
         {
             currentDirection = 
             Vector3.Slerp(currentDirection, desiredDirection, turnSpeed * dTime);
             
             transform.Rotate(0,0,180 * dTime,Space.Self);
             
             duracionGiro.Interpolate();
             
             if(duracionGiro.HasFinished())
             {
                 duracionGiro.Reset();
                 parte2 = false;
                 terminoGiro = true;
                 transform.LookAt(transform.position + currentDirection);
             }
         }
     }
 }

From already thank you very much

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

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

Instantiate Object in direction from another 1 Answer

How do I get an Unity Camera to interact with an Android camera compas funtion 1 Answer

[2D] Get 0-359 compass angle player <--> object 1 Answer

Rotate 2D Texture negative positive degrees touch 2 Answers

Rotate player 360 degrees once 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