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 JoshMBeyer · Jan 24, 2013 at 07:15 PM · gameobjectpositionrotatecursorwith

How can I make my airplane rotate by my cursor position?

I am working on a Aviation Controller. I was wondering how to make it to where if my cursor center location is the screen width / 2, and screen height / 2. So that the center position is the center of the users screen. The farther the cursor is from that center position the more the aircraft will change its rotation. Here is a picture example:

The left is a diagram of what I am saying. The right is the players screen and how it would look to them.

alt text

How would I go about doing this? I can't get much further than,

  Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
example.png (23.7 kB)
Comment
Add comment · Show 1
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 robertbu · Jan 24, 2013 at 08:40 PM 0
Share

Here is quick script to get you started. It does not do exactly what you asked for, but, if attached to the plane, will allow you to rotate the plane by clicking the mouse and moving the cursor. Note it could be attached to an object in the center of the screen with the renderer turned off and the plane could mirror the rotation.

 private var factor : float = 0.6;
 private var v3StartPos : Vector3;
 private var v3StartRot : Vector3;
 private var v3Axes : Vector3 = new Vector3(1,1,0);
 
 function On$$anonymous$$ouseDown(){
        v3StartPos = Input.mousePosition;
        v3StartRot = transform.eulerAngles;
 }
 
 function On$$anonymous$$ouseDrag(){
     var v3T : Vector3 = Input.mousePosition;
     var v3T2 : Vector3 = v3StartRot;
     v3T2.y += (v3StartPos.x - v3T.x) * factor;
     v3T2.x -= (v3StartPos.y - v3T.y)* factor; 
     transform.eulerAngles = v3T2;
 }

A solution that did not require an object with a collider would take a somewhat different approach.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Mons1999 · Jan 24, 2013 at 09:18 PM

You just need to add a "Mouse Look" component that you can find in the imported assets in Compenent => Camera-Control => Mouse Look. Then if you move your cursor your plane will rotate perfectly. If you also want it to move in the same time, also add a "Character Controller" that you can find in Component => Physics => Character Controller, a "Character Motor" and a "FPS Input Controller" in Component => Character. I wish this answer helps you ;)

Comment
Add comment · 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

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

Retrieve the alpha of game objects texture at cursor position 1 Answer

Cannot rotate GameObject from C# Animator attached 1 Answer

Rotate GameObject Issue 1 Answer

Scrolling Sprite Object 0 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