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 Vitruvius · Aug 07, 2010 at 09:36 PM · 2dquaternionangleeulerangles

follow an object's x-axis and have it translate smoothly into another object's z-axis rotation

I'm making a 2.5 side scroll game. Game objects are 3D but the game is essentially 2D.

I have Ship B tracking Ship A's position along the x and y axis. When A moves past B in the side-scroll , I want B to Rotate around it's Y-axis as it is tracking A's movement.

I have script that does this but the Rotation around Z-axis is instantaneous. I need to slow it down to A's speed as it passes B from left to right. Sort of how an helicopter banks to make a turn. I don't need realism, Just need a smooth movement to show Ship B's 3D profile.

public class LookAtTarget : MonoBehaviour { public Transform target;

      void Update()
      {
      float lockPos = 0;
 {
      transform.rotation = Quaternion.Euler(lockPos, transform.rotation.eulerAngles.y, lockPos);
 }

           if(target != null)
           {
                transform.LookAt(target);
           }

      }
 }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Julian-Glenn · Aug 07, 2010 at 11:43 PM

Something like this may work *note not tested javaScript code

var rotationSpeed = 5.0; var theTarget : Transform;

function RotateTowards (position : Vector3) {

     var direction = position - transform.position;
     direction.y = 0;
     if (direction.magnitude < 0.1)
         return;

     // Rotate towards the target
     transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime);
     transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0);
 }

And call it like so:

RotateTowards(theTarget);
Comment
Add comment · Show 3 · 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 Julian-Glenn · Aug 07, 2010 at 11:46 PM 0
Share

You'll have to change the Axis to suit your needs but this will rotate towards the target at whatever speed you wish

avatar image Vitruvius · Aug 08, 2010 at 12:04 AM 0
Share

Thanks for the code but I'm getting an error msg.

The best overload for the method 'LookAtZturn.RotateTowards(UnityEngine.Vector3)' is not compatible with the argument list '(UnityEngine.Transform)'.

avatar image · Aug 23, 2010 at 02:55 AM 0
Share

You should be calling: RotateTowards(theTarget.position); It's expecting a Vector3, but being passed a Transform.

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

No one has followed this question yet.

Related Questions

quaternion.eulerAngles 1:1 angle conversion 1 Answer

How can I draw a line at a specific angle? 1 Answer

Quaternions, Eulers, and SmoothDampAngle 0 Answers

Object makes random jumps in rotation 1 Answer

Euler angle rotation in self space problem. 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