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 Mahtrok · Feb 22, 2012 at 03:11 AM · quaternionquaternion.lookrotationquaternion.slerp

Quaternion Slerp 180 Away from target

I am working on a space flight simulator, at this point i'm trying to get an autopilot running to approach and stop at a defined distance to the target object.

I don't want the possibility to simply brake down the velocity to zero, in case the ship has to stop accelerating, turn arround 180 degrees by a defined turnrate and then start the engines to slow down until it reaches a velocity near zero were it can brake to zero an turn around again to face the target.

     void Update () {
     
     if(Input.GetKeyDown(_control.autoApproach) && !_approach){
         if(_target.selectedTarget != null){
             _target.approachingTarget = _target.selectedTarget;
             _distance = Vector3.Distance(_target.approachingTarget.transform.position, _myTransform.position);
             _way = _distance - _maxDistance;
             
             _approach = true;
         }
         else
             _approach = false;
     }
     if(Input.GetKeyDown(_control.stopAutopilot)){
         _approach = false;
         _MoObj.DefEngineOutput = 0;
     }
     
     if(_approach){            //if approach
         if(!_braking)
             RotateToTarget();    //turn to face target
         Vector3 directionToTarget = _myTransform.position - _myTargetTransform.position;
         float _angle = Vector3.Angle(_myTransform.forward, directionToTarget);
         if (_angle > 179 && _angle < 181){
             MoveToTarget();        //approach till < 2000
         }
         if(_rotateToBrake){
             RotateToBrake();    //Turn around 180°
         }                        
         if(_braking){            //Increase Output to slow Ship down
             _distance = Vector3.Distance(_target.approachingTarget.transform.position, _myTransform.position);                    //CheckDistance
         }    
                                 
                                 //Decrease Output to decrease Speed before arriving at TargetVector
                                 //Arrive at TargetVector by Brake();
                                 //Rotate to View Target
     }
 }

     private void RotateToTarget(){
     if(_target.approachingTarget != null){
         _myTargetTransform = _target.approachingTarget.transform;
         _myTransform.rotation = Quaternion.Slerp(_myTransform.rotation, Quaternion.LookRotation(_myTargetTransform.position - _myTransform.position), _MoObj.TurnRate * Time.deltaTime);
     }
     else{
         _target.approachingTarget = _target.selectedTarget;
         RotateToTarget();
     }
 }

     private void RotateToBrake(){
     
         
     if(_target.approachingTarget != null){

         _myTargetTransform = _target.approachingTarget.transform;
         _myTransform.rotation = Quaternion.Slerp(_myTransform.rotation, Quaternion.Inverse(_myTransform.rotation), _MoObj.TurnRate * Time.deltaTime);
         //_myTransform.Rotate(Vector3.down, _MoObj.TurnRate);     
         
         
         
         
     }
     else{
         Debug.Log("No Target for AutoPilot!");
     }
 }

My actual problem lies in the RotateToBrake() function. I don't get it and its late now. I checked nearly ever type of rotate function Unity comes up with, i tried a 100 times to print out myTransforms.rotation, viewports, rigidbody rotations i tried euler angles, Quaternions, defined angles, simple Transform.Rotate to AddForce Variants. I tried to set a new Gameobject directly behind my ship to use turnto again but somehow i made it wrong. Maybe some1 has an idea how to get the exact direction behind my ship and turn it there in a smooth way like a Quaternion.Slerp();

Or even a completly different Idea how to solve the hole thing...

Greetings Mahtrok

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 DaveA · Feb 22, 2012 at 03:25 AM

Look into Transform.forward. You probably want to negate that to make it 'backward'. Then slerp or RotateTo that. If you want it to 'ease' to a stop, check this out: http://unifycommunity.com/wiki/index.php?title=Interpolate

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Use curve effect on rotation? 1 Answer

Quaternion.LookRotation problem - always rounded to 90 degree angles 1 Answer

Look rotation makes sudden changes 1 Answer

Rotate on X axies towards an objects height in 3D 1 Answer

how to rotate bullet towards target direction?unity2D 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