- Home /
Question by
Catiza · Nov 08, 2019 at 03:14 PM ·
camera-movement
How to make a constantly moving camera?
Hello, I'm stuck with my coding. I'm still a beginner. What I'm trying to make is a player descending. I want to make a long (non-repetitive) background to which the camera moves over. It needs to be constantly moving at a base speed, but when the player presses W or S it goes slower or faster. So far I've managed to get the faster and slower part with the keys, but I have no idea how to tackle the constant moving of a camera. (current code is from a Brackeys tutorial)
public class ScreenDown : MonoBehaviour
{
public float baseSpeed = 5f;
public float speedUp = 0f;
public float speedDown = 0f;
void Update()
{
Vector3 pos = transform.position;
if (Input.GetKey("w"))
{
pos.y += baseSpeed * Time.deltaTime;
}
if (Input.GetKey("s"))
{
pos.y -= baseSpeed * Time.deltaTime;
}
transform.position = pos;
}
}
Comment
Your answer