var canControl = true;
// The character will spawn at spawnPoint's position when needed. This could be changed via
a script at runtime to implement, e.g. waypoints/savepoints.
var spawnPoint : Transform;
class PlatformerControllerMovement {
// The speed when walking
var walkSpeed = 3.0;
// when pressing "Fire1" button (control) we start running
var runSpeed = 10.0;
var inAirControlAcceleration = 1.0;
// The gravity for the character
var gravity = 60.0;
var maxFallSpeed = 20.0;
// How fast does the character change speeds? Higher is faster.
var speedSmoothing = 5.0;
// This controls how fast the graphics of the character "turn around" when the player
turns around using the controls.
var rotationSmoothing = 10.0;
// The current move direction in x-y. This will always been (1,0,0) or (-1,0,0)
// The next line, @System.NonSerialized , tells Unity to not serialize the variable or
show it in the inspector view. Very handy for organization!
@System.NonSerialized
var direction = Vector3.zero;
// The current vertical speed
@System.NonSerialized
var verticalSpeed = 0.0;
// The current movement speed. This gets smoothed by speedSmoothing.
@System.NonSerialized
var speed = 0.0;
// Is the user pressing the left or right movement keys?
@System.NonSerialized
var isMoving = false;
// The last collision flags returned from controller.Move
@System.NonSerialized
var collisionFlags : CollisionFlags;
// We will keep track of an approximation of the character's current velocity, so that
we return it from GetVelocity () for our camera to use for prediction.
@System.NonSerialized
var velocity : Vector3;
// This keeps track of our current velocity while we're not grounded?
@System.NonSerialized
var inAirVelocity = Vector3.zero;
// This will keep track of how long we have we been in the air (not grounded)
@System.NonSerialized
var hangTime = 0.0;
}
var movement : PlatformerControllerMovement;
// We will contain all the jumping related variables in one helper class for clarity.
class PlatformerControllerJumping {
// Can the character jump?
var enabled = true;
// How high do we jump when pressing jump and letting go immediately
var height = 1.0;
// We add extraHeight units (meters) on top when holding the button down longer while
jumping
var extraHeight = 4.1;
var doubleJumpHeight = 2.1;
// This prevents inordinarily too quick jumping
// The next line, @System.NonSerialized , tells Unity to not serialize the variable or
show it in the inspector view. Very handy for organization!
@System.NonSerialized
var repeatTime = 0.05;
@System.NonSerialized
var timeout = 0.15;
// Are we jumping? (Initiated with jump button and not grounded yet)
@System.NonSerialized
var jumping = false;
// Are where double jumping? ( Initiated when jumping or falling after pressing the jump
button )
@System.NonSerialized
var doubleJumping = false;
// Can we make a double jump ( we can't make two double jump or more at the same jump )
@System.NonSerialized
var canDoubleJump = false;
@System.NonSerialized
var reachedApex = false;
// Last time the jump button was clicked down
@System.NonSerialized
var lastButtonTime = -10.0;
// Last time we performed a jump
@System.NonSerialized
var lastTime = -1.0;
// the height we jumped from (Used to determine for how long to apply extra jump power
after jumping.)
@System.NonSerialized
var lastStartHeight = 0.0;
}
var jump : PlatformerControllerJumping;
private var controller : CharacterController;
// Moving platform support.
private var activePlatform : Transform;
private var activeLocalPlatformPoint : Vector3;
private var activeGlobalPlatformPoint : Vector3;
private var lastPlatformVelocity : Vector3;
// This is used to keep track of special effects in UpdateEffects ();
private var areEmittersOn = false;
function Awake () {