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 pigi5 · Feb 02, 2011 at 04:15 AM · camerarotationcharacterdirection

Getting 3rd person to look in direction of camera when right mouse clicked

I am trying to make it so that when I click the right mouse button (without dragging) and release, the player imediately rotates towards the camera direction (only y rotation). I currently have it set so that the camera rotates towards the chracter direction when t he right mouse button is clicked (the opposite of what I want). It works perfectly right now, but to do what I want, I think I will need to implement my 3rd person controller script (I used the standard asset one), but I was wondering the following:

  • How to tell the 3rd person script to execute a function from the MouseLook script
  • How to rotate the 3rd person to the camera's Y rotation

Here is my MouseLook script (I wont post the 3rd person controller, it is way too long, and built in the standard assets, so you can go there to see it):

var sensitivityX : float = 10.0; var sensitivityY : float = 10.0;

var minimumX : float = -360.0; var maximumX : float = 360.0;

var minimumY : float = -60.0; var maximumY : float = 25.0;

var minimumScroll : float = 16.0; var maximumScroll : float = 20.0;

private var rotationY : float = 0.0; private var rotationX : float = 0.0; private var mouseScroll : float = 18.0; private var mouseDrag : boolean = false; private var mouseX : float; private var mouseY : float; private var mouseStartVector; private var mouseDownStart : boolean = false; private var mouseWasDown : boolean = false; private var haveOverriden : boolean = false;

function Update () { mouseX += Input.GetAxis("Mouse X"); mouseY += Input.GetAxis("Mouse Y"); if (Input.GetButton ("Fire2")) { if (mouseDownStart == false){ mouseStartVector = Vector2(mouseX,mouseY); mouseDownStart = true; } haveOverriden = true; rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") sensitivityX; rotationY += Input.GetAxis("Mouse Y") sensitivityY; rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); mouseWasDown = true; if (mouseX == mouseStartVector.x && mouseY == mouseStartVector.y){ mouseDrag = false; } else{ mouseDrag = true; } } else{ if (mouseWasDown && mouseDrag == false){ transform.localEulerAngles = Vector3(0,0,0); rotationX = 0.0; rotationY = 0.0; haveOverriden = false; } mouseWasDown = false; mouseDownStart = false; mouseDrag = false; } if (haveOverriden){ transform.localEulerAngles = Vector3(-rotationY, rotationX, 0); } mouseScroll -= Input.GetAxis ("Mouse ScrollWheel"); mouseScroll = Mathf.Clamp (mouseScroll, minimumScroll, maximumScroll); var cameraZoom = Camera.main; cameraZoom.fieldOfView = mouseScroll*20+50; }

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
Best Answer

Answer by pigi5 · Feb 08, 2011 at 11:08 PM

Nevermind, I figured it out. The built in third preson script is really bad and clunky to be honest. I found another one and edited it to my liking. I just set a static variable on that script the the mouseLook script can change to reset the guy's rotation.

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 GameLvr · Apr 01, 2011 at 02:40 PM 0
Share

please share where you found a better one! the one that ships with Unity is just a bad port from the Lerpz tutorial

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

No one has followed this question yet.

Related Questions

Relative Movement Problem 1 Answer

Turning character with transform.Rotate 0 Answers

Rotating a camera that has MouseLook.cs attached 0 Answers

Character Face Camera Direction 1 Answer

Move character in direction its facing 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