Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Pegasos64 · Oct 19, 2015 at 09:40 AM · lerpturrettrackinglaser

Lerp problem when target is behind turret

Hi!

I'm trying to make a 2-part laser turret that follows the given target.

The turret consists of:

  • (BLUE) A fork that rotates around horizontally

  • (RED) An axle that sits on the fork that rotates vertically

  • Emitter which emits the laser, sitting at the barrel of the gun

The problem only occurs when a target passes over the turret or the target is located exactly behind the turret (180 degrees from the original facing direction).

At that point the fork spins quickly around to face the target (working as intended) but the axle rotation speed drops and the turret takes ages to zero in on the target until the target returns to in front of the turret, at which point the turret starts tracking the target correctly again.

What is the specific reason the axle behaves like this?


Below is the method for following the target.

     void FollowTarget()
     {
         //Rotation from Emitter to Target
         var targetRotation = Quaternion.LookRotation(target.position - Emitter.position);
 
         //Cleaning up the rotation for fork-component (moving on y-axis)
         f_targetRotation = targetRotation;
         f_targetRotation.x = 0.0f;
         f_targetRotation.z = 0.0f;
 
         //Cleaning up the rotation for axle-component (moving on x-axis)
         a_targetRotation = targetRotation;
         a_targetRotation.y = 0.0f;
         a_targetRotation.z = 0.0f;
 
         //lerping the Fork and Axle
         Fork.localRotation = Quaternion.Lerp(Fork.localRotation, f_targetRotation, Time.deltaTime * 32);
         Axle.localRotation = Quaternion.Lerp(Axle.localRotation, a_targetRotation, Time.deltaTime * 32);
 
     }

alt text

I'm quite new to Unity so any suggestions and corrections to the code are appreciated :) Thanks in advance!

turret.png (60.7 kB)
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 Pegasos64 · Oct 18, 2015 at 06:07 PM 0
Share

Further testing shows that when the target is exactly above the turret, the fork spins rapidly around a few times until it locks on the target. I think this behaviour is related to the main issue.

I'm thinking my follow-method is missing some handling for these specific situations where the fork cannot decide on what direction to face.

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

31 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

Related Questions

Interpolated movement in a circle 1 Answer

Setting slider value over time using C# script? 0 Answers

Using lerp properly 2 Answers

Mathf.Lerp crashing build? 1 Answer

Vector3.lerp for moving transform 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