Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Rosscoe3 · Aug 14, 2015 at 10:34 PM · mouselookatmouselook

Rotation offset help!

Hi first off i apologize for all the very similar posts recently.. it wouldn't let me delete them after someone had commented :(.. but i have figured out a "mouse look" script.. and it works great.. but there is a slight offset in the way the character looks.. like he is rotated to far to the right.. is there a way i could ad a rotation offset so he would look directly where the mouse is? heres the code:

using UnityEngine; using System.Collections;

public class LookAtMouse : MonoBehaviour {

 private Vector3 inputRotation;
 private Vector3 mousePlacement;
 private Vector3 screenCenter;
 
 void Update () 
 {
     if (Input.GetMouseButtonDown (0)) 
     {
         Look();
         transform.rotation = Quaternion.LookRotation (inputRotation);
     }
 }

 void Look ()
 {
     screenCenter = new Vector3 (Screen.width * 0.5f, 0, Screen.height * 0.5f);
     mousePlacement = Input.mousePosition;
     mousePlacement.z = mousePlacement.y;
     mousePlacement.y = 0;
     inputRotation = mousePlacement - screenCenter;
 }

}

Comment
Add comment · Show 15
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 jmgek · Aug 14, 2015 at 11:26 PM 1
Share
 private Vector3 inputRotation;
  private Vector3 mousePlacement;
  private Vector3 screenCenter;
  
  void Update () 
  {
      if (Input.Get$$anonymous$$ouseButtonDown (0)) 
      {
          
          transform.rotation = Quaternion.LookRotation (Look());
      }
  }
  
  private Vector3 Look ()
  {
      screenCenter = new Vector3 (Screen.width * 0.5f, Screen.height * 0.5f, 0);
      mousePlacement = Input.mousePosition;
      mousePlacement.z = mousePlacement.y;
      mousePlacement.y = 0;
      inputRotation = mousePlacement - screenCenter;
      return inputRotation
  }


I would just fix that up a little bit then try playing with the width and height.

avatar image Rosscoe3 · Aug 17, 2015 at 07:37 PM 0
Share

mm im not sure what to fix.. here are the errors: alt text

screen-shot-2015-08-17-at-33646-pm.png (35.1 kB)
avatar image jmgek · Aug 17, 2015 at 07:46 PM 1
Share

Oh sorry, it was Vector3 not float return type

private Vector3 Look () {

avatar image Rosscoe3 · Aug 17, 2015 at 07:56 PM 0
Share

Thanks that made it work better!! any idea what i should do with the screen height and width?? im messing around with it.. but i can't seem to get it perfect

avatar image jmgek · Aug 17, 2015 at 08:00 PM 0
Share

Just looking it over I am not too familiar with screen height but I think that you should switch the Z to the Y

 screenCenter = new Vector3 (Screen.width * 0.5f, Screen.height * 0.5f, 0);

The positioning in vector 3 goes 'X Y Z' x is left and right. Y is up and down . z is forward and backwards.

Show more comments

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

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

Related Questions

How do I make the character look at the mouse? 0 Answers

Toggle the Y axis Invert in MouseLook.cs with a keystroke? 3 Answers

Showing and Locking Cursor - JavaScript / JS 1 Answer

Third person animation 0 Answers

rotate object on its axis base on x mouse movement 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