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 skyEchuuu · Feb 22, 2014 at 03:58 PM · cameraraycastterrainmouseorbit

Ray camera to Terrain goes Wrong.

Hi guys , I tried to write a script that raycasting camera to terrain(name that point x) and player will move this point x. I am using Orbit camera and i read something that raycasting to terrain with orbit camera is more complex than other camera types. also i am fully locked camera and I wrote code like this and it is worked but When i try to write code on orbit camera it is not worked.

Here is my ray code;

  void mouseToWorld(){

     RaycastHit hit;
     Vector3 mCoo = cam.ScreenToWorldPoint (Input.mousePosition);
     mRay = cam.ScreenPointToRay(mCoo);
     Debug.DrawRay (mRay.origin, mRay.direction*999, Color.yellow);

  }

and here is the Screenshot that shows where ray is casting; (annotation: when i hit play, ray cast is drawing but when i move the mouse , it doesnt move, it is locked to same position) alt text

Thank you for helps :)

ray2.png (418.4 kB)
Comment
Add comment · Show 2
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 · Feb 22, 2014 at 04:04 PM 0
Share

It is unclear what your problem is here. You create a ray, but there is no Raycast() in the code you provide, so we cannot verify how you are finding your hit point. Also if you have multiple camera's in the scene, you need to create your ray using the specific camera the user is using to view the scene.

avatar image skyEchuuu · Feb 22, 2014 at 04:09 PM 0
Share

there is one camera. $$anonymous$$y question is not about hit point, question is why ray is not moving. I assigned with input.mouseposition, but it is like it doesnt respect to mouse input.

1 Reply

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

Answer by robertbu · Feb 22, 2014 at 05:01 PM

The Issue is that you are passing a world point to the ScreenPointToRay() function. Change line 5:

 mRay = cam.ScreenPointToRay(Input.mousePosition);

Note that even with this fix, you will not be able to see this ray in Game view because the camera will always be looking at the ray end-on.

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 skyEchuuu · Feb 22, 2014 at 05:24 PM 0
Share

I want to get like , if hits terrain get hit.point moveToPoint() which makes my character move to hit.point so I must able to hit that ray on where my mouse on the terrain.

thank you for help !! :))

avatar image skyEchuuu · Feb 22, 2014 at 05:27 PM 0
Share

and it is working thanks again :)

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

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

Related Questions

Camera Movement issue 1 Answer

Need help with a mouse orbit script 1 Answer

Raycast Third Person Camera Problem 4 Answers

Unity Android Movement Problem 0 Answers

Touch mouseorbit 5 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