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
1
Question by Pysassin · Jan 30, 2013 at 02:12 AM · rotationai

Is there a way to smoothdamp a lookat?

Right now I am working on an AI scripts and currently have the bot lookat a target once he sees it. The problem is that its done instantly. I would like for it to take a few seconds that would be the reaction time of th ai. Ive used smoothdamp and seen there is a smoothdampangle but wasnt sure how to use it for this purpose. Anyone know how I could acomplish this?

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 springwater · Apr 28, 2016 at 05:24 AM 0
Share

Im using a damping variable with the time.deltatime method..but im not sure of the range for the variable.. is it 0-1... 0r like 1-360? or or what? do lower numbers give you a faster turn? i suppose I could set up a test situation.. but im doing it on fast moving objects, its harder to observe.. I just wish it were here..

2 Replies

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

Answer by Julien-Lynge · Jan 30, 2013 at 02:40 AM

You can use damping with Slerp. Instead of using LookAt with the transform, work with the Transform's rotation, which is a Quaternion. Use the method SetLookRotation - it will return a quaternion / rotation that's you're target - where you want to look. Then take your current rotation (transform.rotation) and this target rotation, and plug them into Slerp, and that's where you can do smooth damping.

http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.SetLookRotation.html

http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.Slerp.html

Comment
Add comment · Show 5 · 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 Pysassin · Jan 30, 2013 at 02:53 AM 0
Share

Thanks a lot

avatar image Julien-Lynge · Jan 30, 2013 at 02:59 AM 0
Share

Sure thing. You're in for some potentially complicated math working with quaternions, so good luck :)

avatar image JGriffith · Nov 12, 2013 at 10:08 PM 0
Share

It's actually not that complicated but you only describe how to actually slerp between two rotations, how do you apply the smooth damp effect?

avatar image Julien-Lynge · Nov 12, 2013 at 10:13 PM 1
Share

You can do it a few ways. You could use a library like iTween (which offers a few different damping curves). You could do it yourself with a simple damping function, using Euler's number. You could use http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$athf.SmoothDamp.html

However you do it, you take the output of your damping function and plug that into the slerp as the last argument.

avatar image 255_ · Nov 19, 2015 at 02:12 PM 0
Share

I like to use a float called "Damping" and multiple it with Time.deltaTime that's smooth and a little adjustable.

avatar image
3

Answer by idbrii · Mar 28, 2018 at 04:00 PM

Using @Julien-Lynge's answer, I came up with this:

 public Transform Target;
 public float RotateSmoothTime = 0.1f;
 private float AngularVelocity = 0.0f;

 // ...

 var target_rot = Quaternion.LookRotation(Target.position - transform.position);
 var delta = Quaternion.Angle(transform.rotation, target_rot);
 if (delta > 0.0f)
 {
     var t = Mathf.SmoothDampAngle(delta, 0.0f, ref AngularVelocity, RotateSmoothTime);
     t = 1.0f - t/delta;
     transform.rotation = Quaternion.Slerp(transform.rotation, target_rot, t);
 }
Comment
Add comment · Show 1 · 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 abusfad · Feb 09, 2021 at 01:03 PM 1
Share

This worked very well. Thanks!

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

16 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

Related Questions

Basic AI Locked Axis 1 Answer

my ai wiggles slightly 1 Answer

Random movment, like mobs in wow 1 Answer

Enemy AI don't collide with objects or rotate. 0 Answers

object pauses at the each way points for a vary short time 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