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 /
avatar image
0
Question by NivGames · Nov 29, 2021 at 06:58 AM · quaternionlerpnewbierotations

want to make a fixed rotation speed in Lerp no matter what the angle is

I'm working on a 2d Project and I'm New to rotations and Quaternoin,I want to make a fixed rotation speed in Lerp no matter what the angle is. Here is my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class enemyScript : MonoBehaviour
 {
     Rigidbody2D rb;
     [SerializeField] GameObject Bullet, Player, FireSpot;
     [SerializeField] float speed, Duration;
     Vector3 Direction;
     Quaternion Position;
     float time = 0;
     float Dot;
 
     void Start()
     {  
         rb = GetComponent<Rigidbody2D>();
 
         Position = transform.rotation;
         Dot = Mathf.Acos(Vector3.Dot(Vector3.right, Direction)) * Mathf.Rad2Deg;
 
     }
 
     void FixedUpdate()
     {
         transform.Translate(-Vector3.right * speed * Time.deltaTime);
 
 
         if (time > 1)
         {
             Position = transform.rotation;
             Dot = Mathf.Atan2(Direction.y, Direction.x) * Mathf.Rad2Deg;
             time = 0;
             print(Duration);
         }
 
 
         time += Time.deltaTime * Duration;
 
         Direction = Player.transform.position - transform.position;
         Debug.DrawRay(transform.position, Direction, Color.cyan);
         Direction.Normalize();
 
 
         transform.rotation = Quaternion.Lerp(Position, Quaternion.Euler(new Vector3(0, 0, Dot - 180)), time);     
     }        
 }

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by NivGames · Dec 11, 2021 at 08:38 AM

 angleDeg = Vector2.Angle(-transform.right,Direction);
 time = Time.DeltaTime / (Duration/angleDeg);
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
avatar image
0

Answer by Captain_Pineapple · Nov 29, 2021 at 10:04 AM

hey there,

you basically just have to divide your Time.deltaTime * Duration by the total angle you want to cover. So assuming that Dot is your total angle your calculation each frame is Time.deltaTime * Duration/Dot and it should work as you then have seconds * (angle/second) /angle in your units. Thus leading to no unit which is what you want.

Comment
Add comment · Show 6 · 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 NivGames · Nov 29, 2021 at 11:36 AM 0
Share

it doesn't work, its just makes the rotation slower

avatar image Captain_Pineapple NivGames · Nov 29, 2021 at 11:50 AM 0
Share

well just realized that Dot is not the delta angle of your rotation. Just calculate that and divide by the total rotation delta instead of Dot

avatar image NivGames Captain_Pineapple · Nov 29, 2021 at 11:57 AM 0
Share

what is Delta angle?

Show more comments

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

136 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

Related Questions

How would I smooth out a Quaternion? 2 Answers

Time.time or Time.deltaTime(Quaternion.Lerp) 1 Answer

Pinball Flipper using Quaternion.Lerp? 1 Answer

My Quaternion.Lerp() doesn't do anything 0 Answers

Quaternion lerp is not rotating my object to the desired rotation? 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