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 Beta_Artist · Sep 26, 2011 at 06:55 PM · rotationvector3

Turning Vectors....

What would I add to this script to have the object turn 45 degrees and move that direction when ever your cursor moves over the object?

 var speed = 5;
 var deer = 10;
 var tap = 100;
 
 
 function Update () {
     transform.position += Vector3.forward * Time.deltaTime * speed;
 }
 
 function OnMouseEnter () {
     speed = 15;
     TotalScoreScript.Points += deer + 10;
 }    
 
 function OnMouseExit () {
     speed = 5;
 }
 
 function OnMouseDown () {
     TotalScoreScript.Points += tap + 100;
 }
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 Bunny83 · Sep 27, 2011 at 01:58 AM

Like @msknapp already mentioned that's how you can turn the character:

 function OnMouseEnter () {
     speed = 15;
     TotalScoreScript.Points += deer + 10;
     transform.Rotate(Vector3.up,45);
 }   
 
 function OnMouseExit () {
     speed = 5;
     transform.Rotate(Vector3.up,-45);
 }

However you forgot to move it in that direction. transform.position is the position in worldspace so it doesn't matter how it's rotated, it will always move the same direction.

You have to use the "rotated" version of forward.

 function Update () {
     transform.position += transform.forward * Time.deltaTime * speed;
 }
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 Beta_Artist · Sep 27, 2011 at 03:55 PM 0
Share

thanks, it worked :D

avatar image
0

Answer by msknapp · Sep 26, 2011 at 07:33 PM

In your function for OnMouseEnter, add

transform.Rotate(Vector3.up,45); // or use -45

In your function for OnMouseExit, add the same line but switch the sign of the angle.

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 Beta_Artist · Sep 27, 2011 at 01:46 AM 0
Share

I added the code and the only thing it did was make the object spin. Is there something I'm missing to make the object change direction its moving?

avatar image Bunny83 · Sep 27, 2011 at 01:50 AM 0
Share

@Beta_Artist: please use comments when you don't want to answer the question! This site is not a forum with discussions. Each question has only one question and (hopefully) many answers. If an answer is not clear enough use comments to communicate.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Convert local forward into world vector 1 Answer

Applying force with respect to angle with the ground? 1 Answer

Workaround for Quaternion.eulerAngles 360 Degree Limit? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Help to figure a logic to achieve a movement. 2 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