Something like the nanosuit...

Hello everybody! Who needs a code for something like the nanosuit in crysis? :?:

I’ve modified the “ridgidbody first person controller” script a bit, so that you can run while pressing shift or sprint and jump about 4 metres heigh when pressing ctrl. But if the suits energy is empty, you must wait until it’s reloaded, etc…

I hope you can use it somewhere! :slight_smile:

var speed = 10.0;
var gravity = 10.0;
var maxVelocityChange = 10.0;
var canJump = true;
var jumpHeight = 2.0;
private var grounded = false;
var newSpeed = 1.5;

var sprint : boolean = true;
var regenerate : boolean = false;
var Energy = 100.0;
var MaxEnergy = 100.0;
var MinEnergy = 25.0;
var displayEnergy : boolean = true;
var EnergyGUI : GUITexture;
var sprintSpeed = 2.5;
private var EnergyGUIWidth = 0.0;

var superJump = 1.0;

@script RequireComponent(Rigidbody)

function Awake ()
{
	rigidbody.freezeRotation = true;
	rigidbody.useGravity = true;
}
function Start ()
{
	EnergyGUIWidth = EnergyGUI.pixelInset.width;
}
function Update () {
	if (sprint == true) {
		if (Input.GetAxis("Vertical")) {
			if (Input.GetKey("left ctrl")) {
				Energy -= 0.5;
				}
			}
		}
		if (Energy <= 0.0) {
		sprint = false;
	}
		if (Energy >= MinEnergy) {
		sprint = true;
	}
	if (regenerate == true) {
		if (Input.GetKey("left ctrl") == false) {
			if (Input.GetKey("left alt") == false) {
				Energy += 0.2;
			}
		}
	}
	if (Energy >= MaxEnergy) {
		regenerate = false;
		}
	if (Energy < MaxEnergy) {
		regenerate = true;
	}
	if (sprint == true) {
		if (Input.GetKeyDown("left ctrl")) {
			if (grounded == true) {
				if (Energy > 0.0) {
					superJump *= 3.0;
					Energy -= 15.0;
					}
				}
			}
		if (superJump > 3.0) {
			superJump = 3.0;
	}
	if (Input.GetKeyUp("left ctrl")) {
		superJump = 1.0;
		}
	if (grounded == false) {
		superJump = 1.0;
		}
	}
}

function OnGUI () {
	if (displayEnergy == true) {
	// Update health gui
	// The health gui is rendered using a overlay texture which is scaled down based on health
	// - Calculate fraction of how much health we have left (0...1)
	var EnergyFraction = Mathf.Clamp01(Energy / MaxEnergy);
	// - Adjust maximum pixel inset based on it
	EnergyGUI.pixelInset.xMax = EnergyGUI.pixelInset.xMin + EnergyGUIWidth * EnergyFraction;
		}
	}

function FixedUpdate ()
{
	if (grounded)
	{
		// Calculate how fast we should be moving
		var targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
		targetVelocity = transform.TransformDirection(targetVelocity);
		targetVelocity *= speed;
		if (Input.GetKey("left shift")) {
			targetVelocity *= newSpeed;
			}
		if (sprint == true) {
			if (Input.GetKey("left ctrl")) {
				if (Energy > 0.0) {
					targetVelocity *= sprintSpeed;					
					}
				}
			}	
		// Apply a force that attempts to reach our target velocity
		var velocity = rigidbody.velocity;
		var velocityChange = (targetVelocity - velocity);
		velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
		velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
		velocityChange.y = 0;
		rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
	
		// Jump
		if (canJump  Input.GetButton("Jump"))
		{
			rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
		}
	}
	// We apply gravity manually for more tuning control
	rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));
	grounded = false;
}

function OnCollisionStay ()
{
	grounded = true;	
}

function CalculateJumpVerticalSpeed ()
{
	// From the jump height and gravity we deduce the upwards speed 
	// for the character to reach at the apex.
	return Mathf.Sqrt(2 * jumpHeight * gravity * superJump);
}

I suppose all you’re missing now is that guys voice. :smile:

Maximum…Ownage!

Maximum response:

Good idea! :slight_smile:

Can you rewrite complete character controller from crysis nanosuit / abillities? and leave //coments whats for what?