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 khos85 · Jan 01, 2014 at 05:38 PM · cameracontrolsmooth followmouse orbit

Mouse orbit + Smooth follow script question

Hi,

I'm using the built in Mouse orbit + Smooth follow Unity scripts, these two are working fine except for one thing. If I click and drag/rotate so the camera rotates around my object, the smooth follow script always makes the camera go back to the original position if I let go of the mouse button. The smooth follow script only seems to want the camera to be in one position if no mouse input is given..and follow the given game object like that.. Is there a way to remember where the current position/angle/rotation is and have the camera stay in that position and hive it follow using this until I click drag again and rotate...

Anyone come across this before or know of a hack/fix?

Cheers, Kim

Comment
Add comment · Show 3
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 · Jan 01, 2014 at 06:02 PM 0
Share

You will have to modify the scripts. If it were me, I'd rewrite the two scripts into a single script, but you might be able to get by with a careful mod. One approach is to add a 'offsetAngle' as a public variable to the SmoothFollow script. This value is used to modify the calculation of 'wantedRotation' on line 32. Then in the $$anonymous$$ouse Orbit script, you would set 'offsetAngle' to the same value as 'x'.

avatar image khos85 · Jan 01, 2014 at 08:54 PM 0
Share

Hi robertbu, many thanks for your quick help, I'll look into this, and post the script if/once I succeed! good idea about the public variable. Will also need to figure out how to use a public variable, is it as simple as defining this var as public and then it'll be seen in all scripts? I think so...

avatar image khos85 · Jan 02, 2014 at 08:03 PM 0
Share

95% there now... In SmoothFollow.js I added/modified: var myval : GameObject; function LateUpdate () { // Early out if we don't have a target if (!target) return; // Calculate the current rotation angles myval = GameObject.Find("$$anonymous$$ain Camera"); var wantedRotationAngle = myval.GetComponent($$anonymous$$ouseOrbit).y; //var wantedRotationAngle = target.eulerAngles.y;

So adding this line: var wantedRotationAngle = myval.GetComponent($$anonymous$$ouseOrbit).y; was the important one, as robertbu suggested.

In $$anonymous$$ouseOrbit.js I had added code to only orbit on mousedown (if (Input.Get$$anonymous$$ouseButton(0)) {) but I could not get the code to work nicely until I removed this line in function LateUpdate (), so now my code code looks like:

function LateUpdate () { // if (Input.Get$$anonymous$$ouseButton(0)) {
if (target) { x += Input.GetAxis("$$anonymous$$ouse X") xSpeed 0.02; y -= Input.GetAxis("$$anonymous$$ouse Y") ySpeed 0.02; y = ClampAngle(y, y$$anonymous$$inLimit, y$$anonymous$$axLimit); var rotation = Quaternion.Euler(y, x, 0); var position = rotation * Vector3(0.0, 0.0, -distance) + target.position; transform.rotation = rotation; transform.position = position; // } }

So it works well now but not sure how I can get the Input.Get$$anonymous$$ouseButton(0) to work again in mouseorbit...I tried moving that line around to several places in the LateUpdate () function but no help.. any ideas anyone?

Thanks Robertbu for your help with this one again.

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

18 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Control camera target from another scripts 1 Answer

2.5d camera control script 1 Answer

Camera Control Help 0 Answers

character switching on collision 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