Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 yacobster101 · Feb 14, 2017 at 07:43 AM · cameramovementcamera-movementspeedspeed up

Camera movement help

Im trying to make my camera speed up gradually till a maximum speed of 2.5f from 0.1f. How would I go round doing this? thanks in advance/

using UnityEngine; using System.Collections;

 public class CameraMovement : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         transform.Translate(Vector2.down * 0.16f);
         if (transform.position.y == 4)
         {
             transform.Translate(-Vector2.down * 0.16f);
         }
         if (transform.position.y == -4)
 
         {
             transform.Translate(Vector2.down * 0.16f);
 
         }
     }
 }
 
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 Oana · Feb 14, 2017 at 08:10 AM

That's a strange script. So if you start from higher than 4, it will go down to 4 and get stuck there, but if you start from lower than 4, it will keep going down, moving twice as fast for 1 frame when at -4? Unless the camera is upside-down or something. I'm not going to touch that part since I am not really sure what you're trying to do with it. Also, since you're using Update, is there a reason you're not using Time.deltaTime to move the camera?

Either way, to answer your question, you could do something like this to speed the camera up:

  public class CameraMovement : MonoBehaviour {
 
       float speed = 0.1f;
       float speedIncrement = 1.1f; //how fast it increments. tweak this number around to make it slower or faster
          
       void Update () {
            if (speed<2.5f) speed*=speedIncrement;
            if (speed>2.5f) speed = 2.5f;
            transform.Translate(Vector2.down * speed);
       }
  }
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 game-dev333 · Feb 14, 2017 at 11:08 AM 0
Share

If you want to change direction

public class Camera$$anonymous$$ovement : $$anonymous$$onoBehaviour {

        float speed = 0.1f;
        float speedIncrement = 1.1f; //how fast it increments. tweak this number around to make it slower or faster
           
        void Update () {
             if (speed<2.5f) speed*=speedIncrement;
             if (speed>2.5f) speed = 2.5f;
            if($$anonymous$$athf.Abs(transform.position.y) >= 4)
             speed = speed *-1;
             transform.Translate(Vector2.down * speed);
        }
   }

ps it looked wired, you may have to change values

avatar image yacobster101 · Feb 14, 2017 at 01:08 PM 0
Share

Hi, I'm using 0.16f because 1f is way too fast. And the camera doesn't move when I use 0.16f with your script. Any ideas to be able to use 0.16f?

avatar image Oana yacobster101 · Feb 15, 2017 at 08:13 AM 0
Share

I'm confused, how are you using 0.16? Could you paste the code?

avatar image yacobster101 Oana · Feb 15, 2017 at 12:41 PM 0
Share

This is the code I'm using, but it isn't working... Do you know any fixes?

     float speed = 0.01f;
     float speedIncrement = 0.1f; //how fast it increments. tweak this number around to make it slower or faster
 
     void Update () {
         if (speed<2.5f) speed*=speedIncrement;
         if (speed>2.5f) speed = 2.5f;
         transform.Translate(Vector2.down * speed);
     }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I add a camera bounce effect every time the player lands? 0 Answers

[2D] Camera movement causes flickering/jittering sprites 2 Answers

Player Movement using lerp 3 Answers

Slow camera move speed? 2 Answers

Movement Backwards is Slower 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