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 blondeh · Nov 26, 2011 at 07:21 PM · raycastmouserotateinverse

Rotate to mouse seems to be inversed

This picture helps show my current setup - alt text

The pole's pivot point is where the sphere is, and I want the pole to rotate to the mouse position when the mouse is over the plane. This is the code -

 public var turnSpeed:Number = 1000;
 private var lookTarget:Vector3;
 
 function Update() 
 {
     var ray:Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     var hit:RaycastHit;
 
     if (Physics.Raycast(ray, hit))
     {
         if (hit.collider.tag == "myPlane")
         {
             lookTarget = hit.point;
         }
     }
     
     // rotate towards target
     var targetRotation:Quaternion = Quaternion.LookRotation(lookTarget);
     var rotationSpeed:Number = turnSpeed * Time.deltaTime;
     
     transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed);
 }

The raycasting part works - the pole only moves when the mouse is over the plane.

The problem is when I point to the top right of the plane then the pole points to the bottom left and visa versa... so basically all the axis seem inversed? Also if the mouse is in the centre of the plain the pole tries to point to the sky but only gets about halfway.

Any help on this would be appreciated!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by turtlelizer · Jan 21, 2012 at 11:34 AM

the raycast can only see u when u are down on the plane, because Physics.Raycast are looking for a collider. So what i didnt to fix it, was making a plane behind the object, there is as big as the screen.

your coding looks fine, even though im a new and a C# programmer (:

try it, maybe helps

Peace mate (:

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Drag Object Via Axis Handles 0 Answers

Raycast with strange Behaviour 0 Answers

I want to click on my screen and make my character move there, having trouble with raycasts. 1 Answer

[Solved]Cursor emulation with canvas? 0 Answers

(C#) 2D Raycast wrong direction 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