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 Dima Antonov · Apr 05, 2010 at 07:29 AM · cameradistancesmoothtransitionheight

Edit SmoothFollow.js to change height and distance vars smoothly on some triggers

SmoothFollow.js is attached to main camera and it looks at player. I have couple of places in the game, that need other height and distance variable values, like I usually have distance 3.0 and height 2.0, than when I enter trigger I want to change camera position smoothly to distance 5.0 and height 0.5. And on trigger exit I want to smoothly change them back.

I've killed couple of hours on this, the values change, but not smoothing at all (except height damping smoothes movement a bit, but it still looks jaggy). Triggering is okay and script called CollisionItem manages it fine, please help me with smoothing part.

// Standart SmoothFollow.js var target : Transform; var distance = 3.0; var height = 2.0; var heightDamping = 2.0; var rotationDamping = 3.0;

//||||||||| My addition to the script. Start |||||||||\\ var normalDistance = 0.0; var normalHeight = 0.0; var spiralDistance = 5.0; var spiralHeight = 0.3; private var mysteriousVelocity = 0.0; var smoothTime = 1.0;

function Start () { normalDistance = distance; normalHeight = height; }

function LateUpdate () { if (CollisionItem.spiralInside) { distance = Mathf.SmoothDamp(normalDistance, spiralDistance, mysteriousVelocity, smoothTime); height = Mathf.SmoothDamp(normalHeight, spiralHeight, mysteriousVelocity, smoothTime); } else if (CollisionItem.spiralExited) { distance = Mathf.SmoothDamp(spiralDistance, normalDistance, mysteriousVelocity, smoothTime); height = Mathf.SmoothDamp(spiralHeight, normalHeight, mysteriousVelocity, smoothTime); } //||||||||| My addition to the script. End |||||||||\\

 // Early out if we don't have a target
 if (!target)
     return;

 // Calculate the current rotation angles
 wantedRotationAngle = target.eulerAngles.y;
 wantedHeight = target.position.y + height;

 currentRotationAngle = transform.eulerAngles.y;
 currentHeight = transform.position.y;

 // Damp the rotation around the y-axis
 currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);

 // Damp the height
 currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);

 // Convert the angle into a rotation
 currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);

 // Set the position of the camera on the x-z plane to:
 // distance meters behind the target
 transform.position = target.position;
 transform.position -= currentRotation * Vector3.forward * distance;

 // Set the height of the camera
 transform.position.y = currentHeight;

 // Always look at the target
 transform.LookAt (target);

}

Comment
Add comment · Show 1
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 xLangox · Oct 17, 2010 at 09:16 PM 0
Share

i also need to know this. i think it is not possible in unity

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DewDrop · Oct 26, 2012 at 09:41 AM

i think you can use global variables, as "var static height" and "var static distance". so you can alter the height and distance from other scripts.

i hope it will help you.

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

1 Person is following this question.

avatar image

Related Questions

How to make sliding room transitions like in Mega Man? 1 Answer

Move along grid where facing 1 Answer

Camera animations transition smoothly? 0 Answers

Easy transition between multiple views? 1 Answer

Smooth Orbit Round Object with Adjustable Orbit Radius 5 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