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 /
avatar image
0
Question by stealthcold · Jul 14, 2011 at 07:29 PM · rotationship

Rotate a ship so cannons can face the objective (another ship)

Hello! I've tried a lot of examples of rotation and I didn't have the expected results. So, here it goes:

I have a ship (parent) and this ship has a cannon (child). The cannon is located at the left side of the ship, their x axis is faced to the orange arrow (as you can see in the example picture). How do I rotate the ships in a way that the cannons face the objective (another ship)? I don't know how to get the correct rotation angle...

I hope you could help me...

=)

The example pic: example pic

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

Answer by aldonaletto · Jul 14, 2011 at 09:36 PM

You can create a rotation from your cannon to the target, then apply it to the whole ship. This script must be attached to the ship, and you must assign the target transform to the target variable:

 var target: Transform; // your target
 var speed: float = 2; // turning speed
 
 function Update(){
 
     var dir = target.position - transform.position; // target direction
     // generate rotation from "transform.left" (doesn't exist) to the target
     var rot = Quaternion.FromToRotation(-transform.right, dir);
     // smoothly turns the ship to the target
     transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime * speed); 
 }

   
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 stealthcold · Jul 15, 2011 at 02:58 PM 0
Share

Hello aldonaletto ! Your tip worked for me! Thanks, thanks, thanks a lot! =)

avatar image flaviusxvii · Jul 15, 2011 at 03:55 PM 0
Share

s$$anonymous$$lthcold.. if aldonaletto answered your question you should ACCEPT it.

avatar image stealthcold · Jul 15, 2011 at 05:16 PM 0
Share

ops.. sorry.. thanks flaviusxvii!

avatar image
0

Answer by almo · Jul 14, 2011 at 08:16 PM

Vector3.RotateTowards any help?

http://unity3d.com/support/documentation/ScriptReference/Vector3.RotateTowards.html

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 stealthcold · Jul 14, 2011 at 09:01 PM 0
Share

First of all thanks for the reply! =)

Well, it rotates.. but the cannon still pointing to the other side... According to the example picture, now the blue arrow is pointing to the target...But I need the orange arrow pointing to the target.. There's a way ?

avatar image almo · Jul 14, 2011 at 09:27 PM 0
Share

If the cannon is an object, can't you use RotateTowards to rotate the cannon towards the player?

avatar image stealthcold · Jul 14, 2011 at 09:30 PM 0
Share

But I have a old pirate ship and the cannons are fixed... =( I should had made a modern ship... damn!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to turn ship smoothly to mouse position when mouse click? 0 Answers

Rotation Speed 1 Answer

How do i keep an object from rotating? 2 Answers

Set rotation based on where player is facing 1 Answer

AddForce to transform.up locks ship at 90/270 degrees (gimbal lock?)... 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