Hello all, recently I’ve been messing around with the FPS walker script and have tried expanding upon it. Strafing causes the camera to tilt in the corresponding direction and moving forward sways the camera back-and-forth. But for some strange reason whenever the camera is moved, it becomes somewhat jittery depending on the X angle of the camera. My guess is that it has to do with “controller.Move”. Could anyone help rid of this problem?
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
var rspeed = 1.0;
var rx = 0.0;
var ry = 0.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
private var zrot = 0.0;
private var sway : boolean = false;
private var moving : boolean = false;
function FixedUpdate()
{
if(grounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if(Input.GetButton ("Jump")) moveDirection.y = jumpSpeed;
}
else moveDirection.y -= gravity * Time.deltaTime;
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
FPS();
}
function FPS()
{
rx += Input.GetAxis("Mouse X") * rspeed;
ry -= Input.GetAxis("Mouse Y") * rspeed;
CameraShake();
transform.rotation = Quaternion.Euler(ry, rx, zrot);
}
function CameraShake()
{
if(grounded)
{
var vert = Input.GetAxis("Vertical");
var hori = Input.GetAxis("Horizontal");
moving = (vert != 0 || hori != 0);
if(hori != 0)
{
if(hori > 0)
if(zrot-- <= -10.0)
zrot = -10.0;
if(hori< 0)
if(zrot++ >= 10.0)
zrot = 10.0;
return;
}
if(vert > 0)
{
if(!sway)
{
if(zrot++ >= 10.0)
sway = true;
}
else
{
if(zrot-- <= -10.0)
sway = false;
}
}
}
else moving = false;
if(!moving)
{
if(zrot < 0)
zrot++;
else if(zrot > 0)
zrot--;
}
}
@script RequireComponent(CharacterController)