Hey all,
I’m fooling around with making a vertical scroller and I was wondering what is the best method or what methods are available.
I’ve been doing it in the following way.
public float gameSpeed = 2f;
private float moveAmount = 0;
void Update ()
{
moveAmount = gameSpeed * Time.deltaTime;
gameCamera.transform.Translate(Vector3.up * moveAmount);
}
The camera speed will change from time to time. Speed up, Slow Down and Stop. At the moment I do this using iTween. But I’m not sure this is the best method.
I was just wondering what is the best way to move the camera?
But multiplying by Time.deltaTime it should maintain a constant speed. Are you moving the camera in another script which is causing the behaviour?
Nope just messing with the camera in that script. I was just wondering if there are better ways to move a camera other then the way I was doing it manually. Don’t really work with 3d much so cameras and movement in 3d space isn’t my strong side, so I don’t really know what the best options are other then what I can think of.
Manually updating the position or treating it like a rigid body and giving it different velocities.
I am still a newbie coder and what I see is from my view the simplest way of doing this, witch should work. I agree with raider that there seems to be something else contributing to this velocity change. You have the speed of 2 and nothing else is changing that value in this script.
I don’t see an easier way of doing it.
Ahh sorry I see what you both are saying. What I meant by
Its not an error occurring. I actually want the speed to change, I was just asking whats a good way to deal with a scrolling camera keeping in mind I want it to be able to Stop, Slow down and speed up etc. I currently use iTween to change the speed value but was just wondering about better methods.
Because its core to my game I just wanted to make sure I was using the most efficient method of doing so.
Sorry I think I may have worded my post badly. Hope it makes a little more sense now. But all good I’ve done tests and the method I’m using seems to run pretty well with the rest of the game.
Thanks for the replies.
Yes - your posted code has a fixed speed, so if the game runs smoothly then the camera will move smoothly.
However, when you change the speed of the camera movement you want that to look smooth.
I have not used iTween, but it will probably provide you with the ease in and out you need for smooth transitions in speed.
Alternately, something like:
public float gameSpeed = 2f;
private boolean slowToStop = true;
if ( slowToStop gameSpeed > 0) gameSpeed = Mathf.Lerp ( gameSpeed, 0, Time.deltaTime);
but notice that gameSpeed has lost its original value - how do you know to get back to 2.0 as the best speed?
public float targetGameSpeed = 2f;
private float currentSpeed = targetGameSpeed;
then only adjust the currentSpeed up and down, and return it to the value of targetGameSpeed when needed (or targetGameSpeed * 0.5, etc.)