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 GameCherry · Apr 19, 2011 at 04:47 AM · cameratransformpositiontimeduration

How To Slow Camera Position Transform?

The main camera changes position when triggered but, too quickly. Is there a way to "slow" the cameras journey to it's new position? Thanks for looking.

var MainCamera : Camera;

var CurveX = 90.0;

var CurveY = 45.0;

var CurveZ = 145.0;

function Update () { }

function OnTriggerEnter (other : Collider) { Camera.main.transform.position = Vector3(CurveX, CurveY, CurveZ); }

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kourosh · Apr 19, 2011 at 11:10 AM

Try this:

var CurveX = 90.0;

var CurveY = 45.0;

var CurveZ = 145.0;

var increment:float;

var moveCam:boolean = false;

function Update () { if(moveCam){

Camera.main.transform.position = Vector3.Slerp(Camera.main.transform.position,Vector3(CurveX, CurveY, CurveZ), increment);

if (increment <1) increment +=0.01;

}

}

function OnTriggerEnter (other : Collider) {

moveCam = true; }

Slerp/Lerp function will smoothly change values.

Check this also:

http://unity3d.com/support/documentation/ScriptReference/Vector3.Slerp.html

Comment
Add comment · Show 2 · 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 efge · Apr 19, 2011 at 11:15 AM 1
Share

You could also try $$anonymous$$athf.SmoothDamp and $$anonymous$$athf.SmoothStep. But would'nt it be better to store the transformation values and apply them during LateUpdate()?

avatar image Kourosh · Apr 19, 2011 at 11:30 AM 0
Share

Well, yes, however I don't really know how different the result would be using each one of these functions. So i just took one. And about the LateUpdate(), are you talking preformance wise or the smoothness of the motion?

avatar image
0

Answer by GameCherry · Apr 19, 2011 at 09:09 PM

Thanks for the reply Kourosh but, this code does nothing. Increasing/decreasing the increment values also has no effect on the camera. I tried adding a camera/target variable like in my original code but, again no difference. So, I changed it around a bit.

I swapped Slerp to Lerp and replaced the increment modifier with Time.deltaTime. This setup works better than my original code in that the camera movement is slowed but, still not slowed enough.

I'm a little confused on Time. It's my understanding that Time.deltaTime is an action done within a certain amount of time were-as Time.time is an action done within a certain amount of frames - is this correct? Either way, no matter how I +,-,,/ the Time factor - the amount of time it takes the camera to "move" to it's new position seems to be the same. (though and / seem to add/subtract distance rather than time)

Here is my modified code as it is now.

var MainCamera : Camera;

var CurveX = 90.0;

var CurveY = 45.0;

var CurveZ = 145.0;

var duration = 1.0;

function Update () { }

function OnTriggerEnter (other : Collider) { Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position,Vector3(CurveX, CurveY, CurveZ), Time.deltaTime + duration);

}

Time.deltaTime + duration does not seem to make the position transition any longer. If anyone could tell me what it is I am doing wrong - it would be greatly appreciated. Thanks everyone for your comments and interest.

Comment
Add comment · Show 2 · 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 Kourosh · Apr 19, 2011 at 09:30 PM 0
Share

Time.deltaTime is the time took to render your last frame. Whereas Time.time is actual time from the beginning of your application. Slerp and lerp functions need an increasing/decreasing factor from 0 to 1 or 1 to 0 to function properly. Yours is not increasing cause lets say Time.deltaTime is roughly 0.2 and it's summed with 1 so it's 1.2 and its done. So you can't see the gradual translation over time. I've edited my code. please check again.

avatar image Kourosh · Apr 19, 2011 at 09:34 PM 0
Share

I noticed the problem, lerp/slerp should be used on those routines that happen every frame. I mistakenly used it in OnTriggerEnter which happens only once.

avatar image
0

Answer by whydoidoit · Apr 01, 2012 at 10:00 PM

I find that I have to do a lot of smoothing from code and don't want the overhead of adding an iTween to the game object.

To help I've built some helper classes which you can take a look at and download here. Basically they let you replace a standard float, Vector3 or Quaternion with a SmoothXXXX version that will use one of four smoothing functions to interpolate between the current and the target position over time.

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

I make a camera that change position every X seconds but i need different waiting time for each position that take. 0 Answers

Camera movement 1 Answer

Place a object in front the camera in the coordinate 0 of Y axis 2 Answers

Trouble converting transform.position to C# 1 Answer

How to make Main Camera to not follow object on Y 3 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