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 Jens Andersson · Mar 07, 2012 at 12:15 PM · vector3velocityangleconvert

Converting vector3 velocity to an angel

I have a cannon that rotates on it's Z value. The thing is that I want the character (that is loaded into the cannon) to get a vector3 velocity depending on the angle of the cannon. So how can I convert that angle into a vector3 velocity?

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

Answer by bateleur · Mar 07, 2012 at 02:47 PM

Typically the easiest way to do this is to use cannon.transform.forward which is a unit Vector3 pointing in the cannon's forward direction.

In your particular case it sounds as though you're doing something odd if your cannon is rotating about the Z axis (which would normally be the facing, to make LookAt work correctly). Consequently you may find you need to reorient your cannon model so that it faces along the forward axis, or alternatively use cannon.transform.right or cannon.transform.up instead as your unit vector depending on which way the cannon model faces.

Of course, the unit vector is unlikely to give you the right launch speed, so you will probably need to multiply it by some scale factor to get the exact launch velocity you want.

Example:

var launchSpeed:float = 3.5;
var myLaunchVelocity:Vector3 = cannon.transform.forward * launchSpeed;

Comment
Add comment · Show 2 · 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 Jens Andersson · Mar 08, 2012 at 08:17 AM 0
Share

The cannon is actually facing the right side of the screen that's why I have the funky axis orientation. Will try this now and see if it works, thanks!

avatar image Jens Andersson · Mar 08, 2012 at 08:27 AM 0
Share

Yupp, worked. Thanks for the help!

avatar image
0

Answer by Meltdown · Mar 07, 2012 at 12:41 PM

So you want to align your player to the cannon?

You can use Quaternion.LookRotation

Something like this...

 var cannonRotation = Quaternion.LookRotation(cannon.transform.right, cannon.transform.up);
 cannonRotation.x = 0;
 cannonRotation.z = 0;
 character.rotation = cannonRotation;

You'll just need to play with the variables to get it right but you get the idea..

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 Jens Andersson · Mar 07, 2012 at 02:25 PM 0
Share

Seems my comment didn't get through for some reason. Anyway, the thing is that I want the angle of the cannon to add a vector3 velocity (like player.velocity = vector3(10,10,0) for example) depending on the angle. I don't want to rotate the character just shoot him in the right angle depending on the cannons angle.

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

Velocity to 2D rotation (angle from velocity vector with atan2) 1 Answer

how to convert the angle to roatation? 1 Answer

get velocity form angle? 1 Answer

force.normalized * magnitude 1 Answer

Velocity powered rigidbody on a moving platform without parenting. 3 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