- Home /
Shake camera up and down when running?
Hello,
I have a big problem. I tried searching for an answer but didn´t find any that could help me.
I would like to "shake" the camera up and down when my character is running, and the faster he´s running the more should the camera shake. I´m not sure how to explain it, maybe almost like Gears of War when your holding A and running.
I have built a script to use a Xbox 360 controller, as show below, but I can´t make i shake when I´m running. Could someone please help me? I´m using C# and not javascript.
// Script
using UnityEngine; using System.Collections;
public class scr_controller : MonoBehaviour {
public float speed = 10;
public float runSpeed = 20;
public float rotateSpeed = 100;
public Transform camera;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update () {
// Movment
float antToRotate = rotateSpeed * Input.GetAxis("HorizontalRight") * Time.smoothDeltaTime;
float antToRotateVert = rotateSpeed * Input.GetAxis("VerticalRight") * Time.smoothDeltaTime;
float antToMove = -speed * Input.GetAxis("Vertical") * Time.smoothDeltaTime;
float antToSideStep = speed * Input.GetAxis("Horizontal") * Time.smoothDeltaTime;
if (Input.GetButton("R_Trigger"))
{
Debug.Log("Press R_trigger");
antToMove = -runSpeed * Input.GetAxis("Vertical") * Time.smoothDeltaTime;
antToSideStep = runSpeed * Input.GetAxis("Horizontal") * Time.smoothDeltaTime;
}
transform.Translate(Vector3.forward * antToMove);
transform.Translate(Vector3.right * antToSideStep);
transform.Rotate(Vector3.up * antToRotate);
camera.Rotate(Vector3.left * antToRotateVert);
}
}
Comment