Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by engri · Aug 17, 2020 at 08:40 PM · vector3slerptransform.rotationtransform.rotate

Substitute transform.rotation + slerp with transform.rotate and Vector3

I am using this method, to rotate ship towards target:

     Vector3 pos = target.localPosition - transform.localPosition;
     Quaternion rotation = Quaternion.LookRotation(pos);
     transform.rotation = Quaternion.Slerp(transform.rotation, rotation, rotationalDamp * Time.deltaTime);

Yet for avoiding obstacles i cast numerous raycasts at different angles grouping them in directions[] array and use (for now simple method that doesn't average out the raycastOffset if there are 2 vectors at the same time, its not important now):

         raycastOffset = Vector3.zero;
         if(free_vectors==0)
             raycastOffset = Vector3.left + Vector3.down;
         else
         {
             if ((directions[1] == true)) raycastOffset += Vector3.left;
             if ((directions[2] == true) && (directions[1] == false)) raycastOffset += Vector3.right;
             if ((directions[2] == false) && (directions[1] == false)) raycastOffset += Vector3.left;

             if ((directions[3] == true)) raycastOffset += Vector3.down;
             if ((directions[4] == true) && (directions[3] == false)) raycastOffset += Vector3.up;
             if ((directions[4] == false) && (directions[3] == false)) raycastOffset += Vector3.down;
         }

[...]

     prev_raycastOffset = (prev_raycastOffset * (1f - (rotate_change_lag * Time.deltaTime))) + (raycastOffset * (rotate_change_lag * Time.deltaTime));
     transform.Rotate(prev_raycastOffset * rotate_speed * Time.deltaTime);

I interpolate the prev_raycastOffset, so that the ship has some drag (regulated by rotate_change_lag) while changing rotation to avoid obstacles. The problem is that when I look towards target with first function, it is clunky and I don't know how to merge these 2 methods (rotation+ Slerp) and transform.Rotate to include my rotation drag. Is it possible to convert the first function, so that it also uses transform.Rotate and an input Vector3 instead of transform.rotate? Then I could incorporate my one drag method for both types of rotations. Or maybe there is a better way?

I was thinking also about using Rigidbody and adding rotation force to achieve those rotations, which would give me much more natural rotation drag effect. It would be more professional, but I don't know even where to begin (not enough experience with it).

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 engri · Aug 18, 2020 at 07:38 AM 0
Share

I spent already 1.5 day on trying to find any solution to this problem among questions in the past and I was open to solutions using any other method. Nothing. I am not surprised nobody even attempts to answer.

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

238 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Move object towards a moving point C# 1 Answer

Change the Rotation X value without changing Y and Z 1 Answer

[SOLVED] How to LookRotation in only Y axis 0 Answers

Strange behavior on cube rotations 0 Answers

Some questions about rotate. 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