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 /
  • Help Room /
avatar image
0
Question by Ejpj123 · Jul 05, 2016 at 07:58 PM · cameraslowprogressmakeof

Make Progression of Camera Slower? (REWARD)

Hi I am making a 2D game, and I am trying to solve something on this script:

 using UnityEngine;
 using System.Collections;
 
 public class MoveCamera : MonoBehaviour {
 
     public float speed = 0.7f;
     public float maxSpeed = 0.7f;
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         Vector3 temp = transform.position;
 
         temp.x += speed * Time.deltaTime;
 
         transform.position = temp;
 
         speed += 0.1f * Time.deltaTime;
 
         //if (speed < maxSpeed)
         //    speed = maxSpeed;
     }
 }
 
 IGNORE THE COMMENTS


As you can see, my camera moves to the right, and moves faster and faster, over time. But the SPEED of the progression of the camera moves to fast. So the transition of the camera moving from slow to fast is to fast. I want that transition of slow to fast for the camera to be slower. Not how slow the camera starts, but the progression of the camera I want to be slow. Is there anything to use other then Time.delta time? Or do I add code, and/or take away code?

I will be giving points for a good answer:

5 points for people who answer within 45 minutes.

3 points for anybody after that.

Make sure it is a good answer, or I will not be giving any points.

Thank your for helping for everybody who helps.

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 Ejpj123 · Jul 05, 2016 at 09:29 PM -1
Share

H E L L O?

avatar image Ejpj123 Ejpj123 · Jul 05, 2016 at 10:27 PM -1
Share

Someone Please Help?

avatar image Ejpj123 Ejpj123 · Jul 06, 2016 at 05:29 PM -1
Share

@Cherno @Aggerwal @duck @3dmodler @wojtask12 @UsmanAbbasi @tanoshimi @Johat @Ga$$anonymous$$g Dudester @RealityStudio @Glurth @gsaccone101 @Dog Gamer @Roxzy @beechnova @$$anonymous$$D_Reptile @rokmarko @SolAZDev @Ali hate

Could anyone one of you guys help me? I'm giving out karma/reputation points for anyone who helps.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TBruce · Jul 06, 2016 at 06:19 PM

This will do what you are looking for (tested). But you will have to tweak the values until you get the exact results that you are looking for.

 using UnityEngine;
 using System.Collections;
 
 public class MoveCamera : MonoBehaviour
 {
     public float speed = 0.01f;
     public float maxSpeed = 0.7f;
     public float speedIncrement = 1.001f; // a value of less than 1 will slow down and not speed up
 
     void Start ()
     {
 
     }
 
     // Update is called once per frame
     void Update ()
     {
         // get the current position of the camera
         Vector3 temp = transform.position;
 
         // change the x position of the camera based on the current speed and time
         temp.x += speed * Time.deltaTime;
 
         // update position
         transform.position = temp;
 
         // if speed is less than maxSpeed increment it
         if (speed < maxSpeed)
         {
             speed *= speedIncrement;
         }
         else if (speed > maxSpeed)
         {
             speed = maxSpeed;
         }
     }
 }

Note: UA notifications has been down almost two weeks now so people that you notified did not get an email because of this.

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 Ejpj123 · Jul 07, 2016 at 04:41 PM 0
Share

Thank you @$$anonymous$$avina, but for some reason no matter what speed I set the camera to, it won't go to that speed, and it won't go faster.

avatar image TBruce Ejpj123 · Jul 07, 2016 at 06:35 PM 0
Share

As I said you will need to tweak the values to get your desired result. The camera does not move to fast with the values that you have (at least not in my tests, I had to use higher values). I do not know how fast you want your camera to go but try these values out to see what I mean

 public float speed = 0.5f;           // starting speed of camera - the higher the value the faster the start speed of the camera
 public float maxSpeed = 40f;         // maximum speed camera wil reach
 public float speedIncrement = 1.01f; // a value of less than 1 will slow down and not speed up, a value greater than 1 progressively speeds up the scamewra

You can play with maxSpeed and speedIncrement in the inspector while the game is running to get your desired results.

Also watch the maxSpeed value in the inspector while the game is playing, This way you know what to cap it at.

Here is an updated version of my original code

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$oveCamera : $$anonymous$$onoBehaviour
 {
     public float speed = 0.5f;           // starting speed of camera - the higher the value the faster the start speed of the camera
     public float maxSpeed = 40f;         // maximum speed camera wil reach
     public float speedIncrement = 1.01f; // a value of less than 1 will slow down and not speed up, a value greater than 1 progressively speeds up the scamewra
     
     private float direction = 1;
 
     void Start ()
     {
         direction = (reverse ? -1 : 1);
         speed *= direction;
     }
 
     // Update is called once per frame
     void Update ()
     {
         // get the current position of the camera
         Vector3 temp = transform.position;
 
         // change the x position of the camera based on the current speed and time
         temp.x += (speed * Time.deltaTime);
         if ($$anonymous$$athf.Abs(speed) < $$anonymous$$athf.Abs(maxSpeed))
         {
             speed *= speedIncrement;
         }
         else if ($$anonymous$$athf.Abs(speed) > $$anonymous$$athf.Abs(maxSpeed))
         {
             speed = ($$anonymous$$athf.Abs(maxSpeed) * direction);
         }
 
         // update position
         transform.position = temp;
     }
 }

I have also included a video so you yould see how it works.

avatar image Ejpj123 TBruce · Jul 08, 2016 at 06:05 PM 0
Share

@$$anonymous$$avina Thank you so much. Just one error though:

Assets/Scripts/$$anonymous$$oveCamera.cs(14,30): error CS0103: The name `reverse' does not exist in the current context

Show more comments
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

72 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 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 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 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

Issue with Rigidbody2D (I think) 2 Answers

My model is shaking 0 Answers

Animated Sprites blocked by Canvas 1 Answer

the camera in game is zoomed in on my player. 0 Answers

code error CS0119 field of view script 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