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 thenachotech1113 · Mar 31, 2013 at 07:15 PM · raycastplaneflight

rotate towards a raycast hit point

hi, I`m trying to make a flight game that works like war thunder with the mouse controls, if you don`t know what is war thunder it is that the plane rotates towards a point set by the mouse position, and the only way i could think on doing it is with a raycast like the following(im a noob with raycasting)

 var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 var hit : RaycastHit;
  
  if (Physics.Raycast (ray, hit, 1000)){
   var rotationLookAt =     Quaternion.LookRotation(transform.position, hit.point);
   Quaternion.Slerp(transform.rotation, rotationLookAt, 6); 
  
 }

please tell me if what am I doing wrong, or if there is a better way. thanks a lot

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

Answer by whydoidoit · Mar 31, 2013 at 07:28 PM

That sounds like a good start to me - normally you will define some plane onto which you wish to cast the ray and set the position.

The best way of just checking that plane is to:

  • Make it a box collider for simplicity

  • Use that box collider's ray cast function to get the position.

This is faster as you only check the one collider and won't have a problem if something is in the way.

If you wanted to set the elevation of an aircraft you might want to make it a box of colliders that follows your camera around (obviously you don't need the face behind you. That way clicking anywhere would cause the aircraft to turn, including upwards etc.

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
avatar image
1

Answer by MountDoomTeam · Mar 31, 2013 at 07:46 PM

perhaps you could do an approach of this kind:

assume that there is a straight line going through the plane travel direction, and then when you click the point on the screen/hover over a point on the screen, you will have another line, either going from the aeroplane or the camera to the mouse position.

you get the point of the mouse position with this function http://docs.unity3d.com/Documentation/ScriptReference/Camera.ScreenToViewportPoint.html one of the camera functions

And then you have 2 lines, the line aeroplane is facing and the new line , and interpolate between the 2 lines.

that said, I'm not exactly sure about the screen to worlds position... http://docs.unity3d.com/Documentation/ScriptReference/Camera.ScreenToWorldPoint.html

I think there is a way to make a raycast jump through everything that doesn't have a certain tag, in which case you could make the skybox have a inwards Collider and to use that? like if you have a giant box, I would understand the above explanation .I was a bit confused about where the plane he was talking about would be.

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 MountDoomTeam · Mar 31, 2013 at 07:48 PM 0
Share

if you have to make an object that stays in front of the aeroplane and that shows where the mouse position is, you would have the position of that mouse object anyway, and take that relative to the plane and interpolate it.

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

13 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 avatar image avatar image

Related Questions

How to hit two object with one raycast? 2 Answers

Mouse plane does not detect height 1 Answer

Create new plane and Raycast in C#? 1 Answer

Help me understand the distance parameter in Plane constructor 1 Answer

Raycast doesn't work from beneath MeshCollider? 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