Hi everyone i need help. I want when my character’s speed is over a number, the view of field of the camera to change. I’m using this script but it works wrong everytime the speed is over 5 it just keeps going from 70 to 80.
var runSpeed: float = 5;
private var lastPos: Vector3;
function Update()
{
var dist = Vector3.Distance(transform.position, lastPos);
lastPos = transform.position;
if (Time.deltaTime > 0)
{
var speed = dist / Time.deltaTime;
if (speed > runSpeed)
{
Camera.main.fieldOfView = 80;
}
if (speed < runSpeed)
{
Camera.main.fieldOfView = 70;
}
}
}
I’m using this to adjust the speed but i need the script to change the view of the field of the camera when im runing and go back to normal when i no longer run.
#pragma strict
var walkSpeed : float = 7; // Regular speed
var sprintSpeed : float = 13; // Run speed
private var charMotor : CharacterMotor;
private var charController : CharacterController;
function Start ()
{
charMotor = GetComponent(CharacterMotor);
charController = GetComponent(CharacterController);
}
function Update ()
{
//Making the actual speed var
var speed = walkSpeed;
//Checking for oppertunity to sprint
if ( charController.isGrounded Input.GetKey("left shift") || Input.GetKey("right shift"))
{
//changing the speed to sprint
speed = sprintSpeed;
}
charMotor.movement.maxForwardSpeed = speed; //Setting the speed
}