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 Callans · Mar 15, 2012 at 06:57 AM · rotationspeedturret

Turret: Getting a constant rotation speed

After doing a tornado twins tutorial, I have code which makes a turrent rotate toward the player. Which is good. But the rotation speed is not constant - the closer it gets to aiming directly at the player, the more it slows down the rotation of the turrent.

I would like it to just use a constant rotation speed until it achieves a perfect aim at the player.

I think the following is the relevant code, but I am not sure. May the unity gods forgive me...

 if (LookAtTarget)
 {
     var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
 
     transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
 }
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
1
Best Answer

Answer by syclamoth · Mar 15, 2012 at 07:02 AM

Yes, that is the relevant code. If you want it to rotate at a constant speed, replace that line with this:

 // assuming you have a variable called 'rotationSpeed'
 transform.rotation = Quaternion.RotateTowards(transform.rotation, rotate, rotationSpeed * Time.smoothDeltaTime);
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 Callans · Mar 16, 2012 at 02:47 AM 0
Share

Hi $$anonymous$$ieren, thanks for your reply!

Well it does seem to rotate at a constant, but it's doing so incredibly slowly (though visibly so). I defined rotationSpeed, setting it to 20, then 2000, but it seems the same very, very slow turning speed in either case (no change in speed)? Were getting somewhere, just need to be able to adjust the turn speed, please!

avatar image syclamoth · Mar 16, 2012 at 04:26 AM 0
Share

Well, keep in $$anonymous$$d that if 'rotate' is close, it will only rotate to that point (no further).

avatar image Callans · Mar 16, 2012 at 05:47 AM 0
Share

Okay, it's weird I open up unity again but this time the turret instantly faces the player character. No turning time at all. I undid all changes back to what the script was at load and it still does it (that's difficult when it appears unity does one thing on the previous edit then another thing on a second load).

I definately don't want the turrent to instantly face the player either (I want it to turn toward them at an even rate of speed). I'm sorry if I'm not getting this. Before it was too slow, now it's instant?

avatar image syclamoth · Mar 16, 2012 at 06:37 AM 0
Share

Well, assu$$anonymous$$g that rotationSpeed is a paramater that you set in the inspector, make sure that it's set to something sane. It occurs to me that if you are assu$$anonymous$$g that changes you make to the initial value in the script file will do anything at all to serialized fields, you could be having problems. Rely on the inspector, not on the code.

avatar image Callans · Mar 16, 2012 at 08:40 AM 0
Share

And yup, there's the tip I need to learn! Watch the inspector, not the script! Yes, it was set to 1 in the inspector - I adjusted it up and it controls the turning speed! Thank you, syclamoth! It's going nicely now! :)

avatar image
0

Answer by Ebil · Mar 16, 2012 at 07:08 AM

Looks like an error which occurs at runtime, then the script isnt used. I also experienced problems i was working on for hours, next day open unity again, and everything is working fine...

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

Rotation used as movement 4 Answers

How to make an object rotate on the y axis towards the mouse? 3 Answers

rotation z of child wont work can some one help me plz 0 Answers

Rotation speed on turret aimed at cursor 1 Answer

question about turret on tank 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