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 Irsan · May 17, 2011 at 04:46 AM · mousesmoothorbit

Smooth Mouse Orbit

Smooth mouse orbit like the default smooth lookat and follow. How is this done?

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
3

Answer by Jean-Fabre · May 17, 2011 at 05:26 AM

Hi,

One way to go about this is to use the smoothDamp system instead of injecting directly the movement to the camera.

Here is a working example:

var target : Transform; var distance = 10.0;

var xSpeed = 250.0; var ySpeed = 120.0;

var yMinLimit = -20; var yMaxLimit = 80;

private var x = 0.0; private var y = 0.0;

var smoothTime = 0.3;

private var xSmooth = 0.0; private var ySmooth = 0.0; private var xVelocity = 0.0; private var yVelocity = 0.0;

private var posSmooth = Vector3.zero; private var posVelocity = Vector3.zero;

@script AddComponentMenu("Camera-Control/Mouse Orbit smoothed")

function Start () { var angles = transform.eulerAngles; x = angles.y; y = angles.x;

 // Make the rigid body not change rotation
 if (rigidbody)
     rigidbody.freezeRotation = true;

}

function LateUpdate () { if (target) { x += Input.GetAxis("Mouse X") xSpeed 0.02; y -= Input.GetAxis("Mouse Y") ySpeed 0.02;

     xSmooth = Mathf.SmoothDamp(xSmooth, x, xVelocity, smoothTime);
     ySmooth = Mathf.SmoothDamp(ySmooth, y, yVelocity, smoothTime);

     ySmooth = ClampAngle(ySmooth, yMinLimit, yMaxLimit);

     var rotation = Quaternion.Euler(ySmooth, xSmooth, 0);

    // posSmooth = Vector3.SmoothDamp(posSmooth,target.position,posVelocity,smoothTime);

     posSmooth = target.position; // no follow smoothing

     transform.rotation = rotation;
     transform.position = rotation * Vector3(0.0, 0.0, -distance) + posSmooth;
 }

}

static function ClampAngle (angle : float, min : float, max : float) { if (angle < -360) angle += 360; if (angle > 360) angle -= 360; return Mathf.Clamp (angle, min, max); }

Now, the camera smoothly follows the target and also smoothly rotates around.

Comments on how to do this better or more efficiently are welcomed :)

Bye,

Jean

Comment
Add comment · Show 6 · 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 Irsan · May 17, 2011 at 11:29 PM 0
Share

Excellent! Where is the camera position affected in the script? I want to remove the smoothing on the follow.

avatar image Irsan · May 17, 2011 at 11:30 PM 0
Share

Also, the Y limits aren't working.

avatar image Jean-Fabre · May 18, 2011 at 05:25 AM 0
Share

in a rush, quickly editing and fixed. But will double check in a couple of hours.

avatar image charlesanjos · Nov 21, 2013 at 07:13 PM 0
Share

awesome! thank you very much!

avatar image twdorado · Dec 16, 2013 at 08:13 PM 0
Share

Whats about collision detection?

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Camera orbit around clicked position 0 Answers

Trouble with moving the camera. 2 Answers

Is it possible to add zoom to the mouse orbit script? 2 Answers

Smooth Camera Movement script with problem. 0 Answers

2d Spaceship smooth mouse 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