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 CapCorn999 · May 30, 2011 at 03:06 PM · cameralagdelaysmoothingflight sim

how do you add camera lag or delay for flight sim

Hi, I am pretty new to scripting and unity but have done some tutorials etc. I am trying to make a flight sim and have made the movement controller for the plane without too many problems. My problem is that the plane looks fixed in the viewport so I want to add some delay to the camera instead of just parenting it to the plane. I have written this script and attached it to the camera:

Code:

 var targetObject : Transform;
 
 function Update() {
 
 Follow();
 }
 function Follow () {
 
   transform.position = targetObject.position;
   transform.rotation = targetObject.rotation;
   
 }

I have tried using - yield WaitForSeconds(1); - with the script but it just seems to make the camera wait 1 second and jump behind the plane. Can anyone help me add some lag to the script or suggest another way of achieving camera lag? Thanks

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

Answer by Rodin · May 30, 2011 at 03:59 PM

We will need a way to store the route of the plane for the last second or so, and 'playback' this route to the camera, with some delay.

To get you started, lets create two arrays in which we will store the position and rotation of the plane for each point in time. And a variable controlling how much lag the camera will have (in frames for the time being):

 var prevPositions = Array();
 var prevRotations = Array();
 var cameraLag = 100;    

Then, in the Update function, lets append the current position and rotation to the arrays, and retrieve the position and rotation as it was 100 frames ago:

 function Update() {
     prevPositions.Push(targetObject.position);
     prevRotations.Push(targetObject.rotation);

     if(prevPositions.length > cameraLag) {
         // .Shift() returns and removes the first element in an array
         transform.position = prevPositions.Shift();
         transform.rotation = prevRotations.Shift();
     }
 }

This is not a perfect solution (it is slow and the camera lag is specified in frames, not seconds), but one that is easy to understand and may put you on the right track.

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 AssassinKnifeV2 · Sep 12, 2015 at 07:12 PM 0
Share

Noob question but how to i import that to my game @Rodin

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 Movement Smoothing 1 Answer

Particles lag/stutter - choppy movement 3 Answers

iOS : Delayed response to touch began? 1 Answer

Socket received data being displayed in game with large delay, how can I synchronize it better?,Unity not synchronously receiving/displaying data from socket 1 Answer

Trouble with logic related to my camera smoothing 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