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.
@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.
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.
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.
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.
@$$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
Your answer
Follow this Question
Related Questions
Issue with Rigidbody2D (I think) 2 Answers
My model is shaking 0 Answers
Animated Sprites blocked by Canvas 1 Answer