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 CarlLawl · Jun 21, 2011 at 03:12 PM · raycastmouselookat

Lookat mouse, without raycasting?

Is there a way to make the player look at the mouse without using raycasting? For instance, if our player is walking along a narrow platform in a tds, it wont look at the mouse unless the mouse is over the platform?

Would there be a way around this? If you're giving examples could you please give them in C#, much appreciated.

Carl

additional info

Apologies I meant rotate the player! i tried to have a go at using the raycasting but i couldnt get it working,

 transform.rotation = Quaternion.Slerp(transform.rotation, 
                        Quaternion.LookRotation(hit.point - transform.position), 
                        rotateSpeed * Time.deltaTime);
Comment
Add comment · Show 7
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 flaviusxvii · Jun 21, 2011 at 06:38 PM 0
Share

Your question is confusing. Are you talking about having the camera look at the mouse position only if it is over a platform? Or are you talking about making some "Player" Game object face the mouse position, only if it is over a platform?...

Take some time with your question to make it clear.

avatar image Chris D · Jun 21, 2011 at 06:42 PM 0
Share

Is there a reason that you don't want to raycast other than it isn't working for narrow platforms? If not, my solution should work....

avatar image flaviusxvii · Jun 21, 2011 at 07:11 PM 0
Share

I don't even know how you understand what he's asking. I guess it "should work" assu$$anonymous$$g what you're assu$$anonymous$$g is assumed correctly.

avatar image Chris D · Jun 21, 2011 at 08:02 PM 1
Share

as I understand it, he's using raycasting for his mouse-look script in a top-down shooter (tds). The problem is that, for narrow platforms, there's no geometry (on either side of the platform) for the raycast to hit, therefore the mouse-look will stop working.

For my answer, I recommend that he detaches the mouselook from being dependant on the level geometry and, ins$$anonymous$$d, has it looking for hits on a plane that is made to be a child of the camera (so it moves with the scene) and avoid the problem.

avatar image flaviusxvii · Jun 21, 2011 at 08:09 PM 0
Share

"as I understand it"... a.k.a. "What I'm assu$$anonymous$$g is..."

Haha.. no progress towards understanding. I love your answer. I'd like to take it to dinner and stuff. But it's all hinged on an ambiguous question.

Show more comments

2 Replies

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

Answer by Chris D · Jun 21, 2011 at 04:23 PM

I'd say, just create a plane (invisible, behind all your other objects, parented to your camera so it moves with the player character) and raycast to that. There won't really be much code difference associated with that change and you'll always be guaranteed to hit something.

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 Chris D · Jun 21, 2011 at 09:46 PM 0
Share

Ok, I'm just going to toss out some functions that I think you should check out:

  1. ScreenToWorldPoint

  2. Transform.LookAt

Also, these questions are for similar games - see if there's something you can adapt to yours:

  1. http://answers.unity3d.com/questions/59652/look-at-mouse-problem.html

  2. http://answers.unity3d.com/questions/60486/look-at-the-mouse.html

avatar image
0

Answer by Waz · Jun 21, 2011 at 11:20 PM

You dont need a real plane nor any raycasting at all. Just use Camera.ScreenToWorldPoint, noting that x,y is mouse and z is distance from camera to an imaginary plane where you want the player to look. If this plane is not fixed, calculate the distance from the players current z distance.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

smooth raycast LookAt ? 1 Answer

LookAt mouse, with run animation 1 Answer

How to make a line renderer (laser beam) smoothly follow the mouse? 1 Answer

how will my camera to move in the direction of dragging? 0 Answers

Turn in the direction of movement 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