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 Pichuscute0 · Sep 29, 2016 at 08:50 AM · c#raycastmousepositiononmousedownonmouseover

Use OnMouseOver or Raycasting while also displaying a camera texture.

I've been making a first-person grid-based dungeon crawler that has a limited-range mouse look. When using this mouselook, which rotates the camera within certain ranges, I'd like to be able to allow for the player to click on objects to interact with them.

The problem is, my game also employs a graphics style where the main camera renders to a texture that is then rendered onto a plane and displayed on-screen by a secondary camera. This seems to make any OnMouse function not fire at all, while making any ScreenPointToRay/ScreenToWorldPosition conversions extremely offset and unusable.

Does anyone know of any settings or workarounds that would allow both the secondary camera to still be the one rendering, while also allowing for positional mouse tracking?

EDIT: The amount of offset seems to be tied to the resolution of the target texture of the camera for some reason.

Comment
Add comment · Show 4
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 chillersanim · Sep 29, 2016 at 11:59 AM 0
Share

Could you provide some sketches and code samples to describe your problem?

How do you transform the mouse position to the ray start and direction?
How do you fire the rays?
What does the setup look like?
What happens so far?

avatar image Pichuscute0 · Sep 29, 2016 at 07:56 PM 0
Share

Sorry about that. I'd gotten some incorrect information, it seems.

But anyway, I had an issue with raycasts, but I think its caused by a more fundemental issue. Because my On$$anonymous$$ouseOver function also just doesn't fire at all.

When I was raycasting, I was just doing in javascript:

 ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 if (Physics.Raycast(ray, hit, 5.0)){
      if (hit.transform.tag=="interactor"){
           Debug.Log("hit");
      }
 }

As far as I could tell, that's all that needed to be done. But the direction was wildly offset. The game takes place in a hallway, and if I click the wall at the back-end of the hallway (roughly the center of the screen), I ins$$anonymous$$d get a raycast that shoots off toward the right wall.

To be clear, On$$anonymous$$ouseOver and raycasting seems to work correctly when I disable my camera's target texture, so there must be something else going on.

avatar image Pichuscute0 · Oct 04, 2016 at 06:52 AM 0
Share

Anybody have any idea why this might be happening?

avatar image chillersanim Pichuscute0 · Oct 04, 2016 at 08:56 AM 0
Share

Hello Camera.main is the active rendering camera.
As you render to a texture which again is rendered in the main camera, you are shooting rays at the texture.

In order to shoot rays from the actual scene camera, you need to calculate the mouse position on the render texture, convert that to the camera space and then fire a ray from that scene camera.

Why are you using two cameras at all?
Wouldn't it be easier to directly use the scene camera as main camera?

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

OnMouseDown for Right Mouse 2 Answers

Distribute terrain in zones 3 Answers

[SOLVED] Raycast only hits one side of the box collider 1 Answer

Looping and closing walls 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