Hello, i want to create camera moving like in facebook game “FarmVille”. Can someone give me a tip or link to tutorial how to create it?
Here’s a pretty simple way to do it:
if(Input.GetKey("a")) transform.position.x -= Time.deltaTime * 100;
if(Input.GetKey("d")) transform.position.x += Time.deltaTime * 100;
Basically the idea is to modify the camera’s transform.position. You can do it with several functions, that was just a direct variable manipulation. I wrote it like that,because I tought it should be easier to understand.
Check the Transform and the Input class, you should find better methods there
And I know it’s not with the mouse, you could use Input.GetAxis(“MouseX”) for example and sum it with the transform.position in this case.
u mean like this:
function Update () {
var h : float = Input.GetAxis ("Mouse X");
var v : float = Input.GetAxis ("Mouse Y");
transform.Translate (v, h, 0);
}
Ok. I tested and thats the code:
var speed : float = 2.0;
function Update () {
if(Input.GetAxis("Fire1"))
{
var h : float = speed * Input.GetAxis ("Mouse X");
var v : float = speed * Input.GetAxis ("Mouse Y");
transform.Translate (h, 0, v);
}
}
Thanks for the help