Good afternoon all, I have added a smoothcamera to my main camera in the game (Follows my space ship) But it does not have any effect at all, This is the 3rd script I have tried (Making me thing its an issue with my object or control method) Is there any special properties that are needed to get a smooth camera working? IT is a standard object with a rigid body, The target is set to my ship. This is my control script, and the scrip for the smooth camera (for space ships) is here http://wiki.unity3d.com/index.php/SmoothFollow2 (at the bottom)
public class ShipController : MonoBehaviour
{
#region Speeds
float TurnSpeed = 0.25f;
float maxSpeed = 10.0f;
float maxSpeedReverse = -1.0f;
float maxTurn = 1.0f;
float horizontalSpeed = 4.0f;
float verticalSpeed = 4.0f;
public float CurrentThrotte = 0.0f;
#endregion
void Start ()
{
rigidbody.useGravity = false;
}
void OnGUI ()
{
GUI.Label (new Rect (20, 10, 200, 25), "Current Speed: " + CurrentThrotte.ToString());
}
void Update ()
{
float h = horizontalSpeed * Input.GetAxis ("Mouse X");
float v = verticalSpeed * Input.GetAxis ("Mouse Y");
rigidbody.AddRelativeTorque (new Vector3 (-v, h, 0) * TurnSpeed, ForceMode.Force);
}
void FixedUpdate ()
{
CheckControlInput();
}
private void CheckControlInput()
{
if(Input.GetKeyUp(KeyCode.F))
{
SendMessage("CanExitCheck",true);
CurrentThrotte = 0.0f;
}
//Prevent ship going over top speed
if (rigidbody.velocity.sqrMagnitude > maxSpeed * maxSpeed)
rigidbody.velocity = rigidbody.velocity.normalized * maxSpeed;
//Prevent ship rotating over top speed
if (rigidbody.angularVelocity.sqrMagnitude > maxTurn * maxTurn)
rigidbody.angularVelocity = rigidbody.angularVelocity.normalized * maxTurn;
if (Input.GetKey (KeyCode.Q))
rigidbody.AddRelativeTorque (new Vector3 (0, 0, maxTurn), ForceMode.Force);
if (Input.GetKey (KeyCode.E))
rigidbody.AddRelativeTorque (new Vector3 (0, 0, -maxTurn), ForceMode.Force);
if (Input.GetKey (KeyCode.W))
rigidbody.AddRelativeForce (Vector3.up * maxTurn, ForceMode.Force);
if (Input.GetKey (KeyCode.S))
rigidbody.AddRelativeForce (Vector3.down * maxTurn, ForceMode.Force);
if (Input.GetKey (KeyCode.A))
rigidbody.AddRelativeForce (Vector3.left * maxTurn, ForceMode.Force);
if (Input.GetKey (KeyCode.D))
rigidbody.AddRelativeForce (Vector3.right * maxTurn, ForceMode.Force);
if(Input.GetKey(KeyCode.PageUp) && CurrentThrotte < maxSpeed)
CurrentThrotte += 0.1f;
if(Input.GetKey(KeyCode.PageDown) && CurrentThrotte > maxSpeedReverse)
CurrentThrotte -= 0.1f;
if(Input.GetKey(KeyCode.Backspace))
CurrentThrotte = 0.0f;
ApplyForce();
}
void ApplyForce()
{
rigidbody.AddRelativeForce (Vector3.forward * CurrentThrotte, ForceMode.Force);
}
}