Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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
1
Question by Adam Bruns · Apr 01, 2010 at 01:50 AM · rotationquaternionruntimejavascript-specific

object facing wrong way, Java script Quaternion

so i got an issue with a turret in my game, i want it to look at the person and shoot, obviously. Well its looking to the left (from its prospective, right from mine) when it should be looking at me. Here is the update function i have (LookAtTarget is a transform var set as the player)

function Update() { if(LookAtTarget) { var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);

         transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
         var seconds : int = Time.time;
         var oddeven = (seconds % 2);
         if(oddeven)
         {
             Shoot(seconds);
         }
     }

so yeah need a way to constantly make its rotation 90 degrees more to look at me, please help

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
3
Best Answer

Answer by duck · Apr 01, 2010 at 09:52 AM

Well, the best way of fixing this would be to fix the orientation of your model's pivot, in your 3D app.

If that isn't possible, you can adjust the target quaternion by adding a line like this. I've changed your var name to "targetRotation" because it's a better description of what the variable contains.

function Update() { if(LookAtTarget) { // calculate rotation towards target var targetRotation = Quaternion.LookRotation(LookAtTarget.position - transform.position);

     // adjust rotation by 90 degrees around y axis
     targetRotation *= Quaternion.Euler(0,90,0);

     transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * damp);

     var seconds : int = Time.time;
     var oddeven = (seconds % 2);
     if(oddeven)
     {
         Shoot(seconds);
     }
 }

}

(and use -90 instead of 90 if it's rotated in the wrong direction!)

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 Adam Bruns · Apr 01, 2010 at 06:59 PM 0
Share

thanks, i went in and tried to change the rotation in blender, but for some reason it just changed the rotation in unity too, not the actual models rotation, so i ended up rebuilding the turret to face the right direction in blender (from front view straight up is forward...) because i was tired of waiting :P still thank you and i'll remember this for later :D

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

Basic quaternion question 1 Answer

Alternative to Quaternion.LookRotation() ? 2 Answers

Longest distance rotation problem: From -175 to 175 via 0 using Quaternion.RotateTowards stops at 5, why? 2 Answers

why is my character rotation always 180° after joystick is released. 1 Answer

[Solved] Help on a rotation issue for a Top-Down view? 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